Aspectj在Controller中失效?
首先给出我的AOP切面在ApplicationContext中的定义:
XML
<aop:aspectj-autoproxy proxy-target-class="true" /> <!-- aop logger --> <bean id="sbeatLog" class="sbeat.util.helper.SbeatLog" /> <aop:config> <aop:aspect id="logAspect" ref="sbeatLog"> <aop:pointcut expression="execution(* sbeat.service.*.*(..))" id="sbeatLogPointcut"/> <aop:before pointcut-ref="sbeatLogPointcut" method="doBefore"/> <aop:around pointcut-ref="sbeatLogPointcut" method="doAround"/> <aop:after pointcut-ref="sbeatLogPointcut" method="doAfter"/> </aop:aspect> </aop:config>
然后切面程序在Unit test里运行正常,但是到了controller里就毫无反应,经过排查,我发现把dispatcher-sevlet.xml里的一句话改动就修复了:
XML
之前 <context:component-scan base-package="sbeat"> <!-- 只扫描Controller --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /> </context:component-scan> 之后 <context:component-scan base-package="sbeat.controller"> <!-- 只扫描Controller --> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice" /> </context:component-scan>
但有哪位高人告诉我是怎么回事?
akaxxx
9 years, 11 months ago