小弟不才,最近学习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>
百思不得其解,求大神指点!!