Spring的xml配置一个小问题
?
<bean id="pureAudience" /> <aop:config> <aop:aspect ref="pureAudience"> <aop:pointcut id="performance" expression="execution(* *.perform(..))" /> <aop:before method="takeSeats" pointcut-ref="performance" /> <!-- pointcut="execution(* *.perform(..))" />--> <aop:before method="turnOffCellPhones" pointcut-ref="performance" /> <!-- pointcut="execution(* *.perform(..))" />--> <aop:after-returning method="applaud" pointcut-ref="performance" /> <!--pointcut="execution(* *.perform(..))" />--> <aop:after-throwing method="demandRefund" pointcut-ref="performance" /> <!--pointcut="execution(* *.perform(..))" />--> </aop:aspect> </aop:config> </beans>
?这里<aop:before>的pointcut指向了aop:pointcut,如果已经有了像这样的
?
<aop:aspectj-autoproxy /><bean id="audience" />
?audience的代码如下:
?
import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;@Aspectpublic class Audience {public Audience() {}@Pointcut("execution(* *.perform(..))")public void performance() {}@Before("performance()")public void takeSeats() {System.out.println("The audience is taking their seats.");}@Before("performance()")public void turnOffCellPhones() {System.out.println("The audience is turning off their cellphones");}@AfterReturning("performance()") public void applaud() {System.out.println("CLAP CLAP CLAP CLAP CLAP");}@AfterThrowing("performance()")public void demandRefund() {System.out.println("Boo! We want our money back!");}}也声明了@Pointcut("execution(* *.perform(..))"),能否让<aop:before>的使用这个Pointcut呢?
暂时来看,指不到,估计没有生成一个叫做performance的pointcut。运行时直接报错。
?