使用spring的aspectj框架实现aop和使用基于aspectj的传统aop开发会产生冲突吗?
2018-08-19 16:01
543 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/JamesLoganHowlett/article/details/81838735
小弟不才,最近学习spring框架的aop实现,然后在进行练习时分别使用spring框架的aspectj实现aop(以下简称框架),基于aspectj的传统aop开发(以下简称传统),我将他们都配置在了同一颗applicationContext.xml文件中,结果发现,如果当传统和框架两种配置同时存在的时候,传统的配置可以生效正常运行,框架的会报错,如果将传统的配置注释掉,框架的就可以正常运行,对此小弟很疑惑,想请教下大神们这是为什么?下面附上配置文件;
aop1.xml,框架的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean name="userTarget" class="cn.itheima.aspectj.IUserImpl"></bean> <bean name="userAdvice" class="cn.itheima.aspectj.UserAdvice"></bean> <aop:config> <aop:aspect ref="userAdvice"> <aop:pointcut expression="execution(* *.add(..))" id="MyCut"/> <aop:before method="before" pointcut-ref="MyCut"/> </aop:aspect> </aop:config> </beans>
aop2.xml,传统的配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean name="helloWorld1" class="exercise.HelloWorldImo1"></bean> <bean name="helloWorld2" class="exercise.HelloWorldImo2"></bean> <bean name="proxyHello" class="exercise.ProxyHello"></bean> <bean name="helloWorldPointCut" class="org.springframework.aop.support.NameMatchMethodPointcut"> <property name="mappedNames"> <list> <value>doPrint</value> <value>printHelloWord</value> </list> </property> </bean> <bean name="helloWorldAspectj" class="org.springframework.aop.support.DefaultPointcutAdvisor"> <property name="advice" ref="proxyHello"></property> <property name="pointcut" ref="helloWorldPointCut"></property> </bean> <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"></bean> </beans>
spring的配置文件,applicationContext.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:c="http://www.springframework.org/schema/c" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <import resource="./aop1.xml"/> <import resource="./aop2.xml"/> </beans>
百思不得其解,求大神指点!!
相关文章推荐
- 学习Java框架的笔记(Spring AOP)简介、动态代理、基于代理类的AOP实现、AspectJ开发
- Spring(十二)AspectJ框架开发AOP(基于注解)
- 基于Spring AOP和Groovy日志模板配置的日志记录框架的二次实现与使用案例
- JAVAWEB开发之Spring详解之——AOP底层剖析(基于JDK和cglib)、Spring中的AOP以及基于AspectJ的AOP实现、Spring的JDBCTemplate详解
- Spring(十一)AspectJ框架开发AOP(基于xml)
- 学习Java框架的笔记(Spring AOP)基于代理类的AOP实现、AspectJ开发(2)、ApectJ注解式声明
- 框架 day37 Spring3,AOP,代理模式(动态/CGLIB/工厂bean),传统AOP,AspectJ框架(基于xml/注解),切入点表达式,jdbcTemplate
- Spring AOP编程(两种:1,传统的AOP切面编程 2,基于aspectj框架切点传统开发)
- Java的静态代理、动态代理,CGLib的动态代理,使用动态代理基于AOP的AspectJ框架—深入探究
- spring心得10--使用Aspectj进行AOP开发介绍及案例分析
- Spring3.1 使用AspectJ实现AOP
- Spring系列之 (九):AOP实现方式(一):使用AspectJ的xml方式
- Spring中使用AspectJ实现AOP
- SSM框架项目搭建系列(六)—Spring AOP之基于XML的声明式AspectJ
- 基于Metronic的Bootstrap开发框架经验总结(16)-- 使用插件bootstrap-table实现表格记录的查询、分页、排序等处理
- SSM框架 基于spring-AOP 实现requet参数日志记录
- Spring基础学习(九)——基于AspectJ的两种AOP实现方式
- Spring_Spring与AOP_AspectJ基于XML的实现
- [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.
- 学习《spring 3.x企业应用开发实战》之基于@AspectJ和Schema的AOP