`
lijunabc
  • 浏览: 47223 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

今天在调试spring aop程序时所犯错误总结

阅读更多
今天在调试spring aop程序时,起初认为context:component-scan部分是扫描@Component,因此其base-page 配置成@Component的包,结果怎么也出不来结果,到spring官方论坛上看到有人求助类似的问题,看到他的配置里面多了一个<bean id="loginAspect" class="com.aabnn.aspect.LogAspect"/>,就把他的拷贝过来,结果出来了,非常高兴。下午吃完饭,又开始调试,弄明白了起初理解的不对,    <context:component-scan base-package="com.aabnn.aspect">
    <context:include-filter type="annotation"
       expression="org.aspectj.lang.annotation.Aspect" />
    </context:component-scan>和<bean id="loginAspect" class="com.aabnn.aspect.LogAspect"/>原来实现相同的功能。同时也发现
<aop:aspectj-autoproxy/>和
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>实现的也是相同的功能。

<?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:context="http://www.springframework.org/schema/context"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
           ">
 	<aop:aspectj-autoproxy/>
 		<!--启用spring对@AspectJ风格的切面配置支持,有两种方式,一种是上面的基于xml命名空间的方式,另一种是以bean的方式配置在容器中,如下面所示。  -->
 	<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator"/>
    <context:component-scan base-package="com.aabnn.aspect">
    	<context:include-filter type="annotation"
    	   expression="org.aspectj.lang.annotation.Aspect" />
    </context:component-scan>

	<!--切面配置的两种方式,一种是上面的基于xml命名空间的方式,一种是下面这种以bean的方式配置在容器中。  -->
	<bean id="loginAspect" class="com.aabnn.aspect.LogAspect"/>
    <bean id="chinesePerson" class="com.aabnn.entity.Chinese"/>
</beans>
分享到:
评论
1 楼 pyzheng 2011-06-16  
谢谢,今天被这个问题折磨死去活来

相关推荐

Global site tag (gtag.js) - Google Analytics