使用spring的aspectj框架实现aop和使用基于aspectj的传统aop开发会产生冲突吗?

小弟不才,最近学习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>

百思不得其解,求大神指点!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值