我在练习aop的helloworld的例子的时候,按你的aop标签配置的方式,总是无法拦截到方法执行前和执行后。程序执行结果只是打印helloworld。也没有报告错误。
另外,spring3.2.3已经不提供dependencies包了,我把之前版本的dependencies包中相关的jar都放到了目录下了。您估计是怎么回事呢?怎么拦截不到呢?
谢谢!
package a;
public interface IHelloService {
public void sayHello();
}
package a;
public class HelloService implements IHelloService {
@Override
public void sayHello() {
// TODO Auto-generated method stub
System.out.println("Hello World!");
}
}
package a;
public class HelloWorldAspect {
public void beforeAdvice()
{
System.out.println("befor advice");
}
public void afterAdvice()
{
System.out.println("after Advice");
}
}
<?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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<bean id="hello" class="a.HelloService"/>
<bean id="aspect" class="a.HelloWorldAspect"/>
<aop:config>
<aop:pointcut id="pointcut" expression="execution(* a..*.*(..))"/>
<aop:aspect ref="aspect">
<aop:before pointcut-ref="pointcut" method="beforeAdvice"/>
<aop:after pointcut="execution(* a..*.*(..))" method="afterAdvice"/>
</aop:aspect>
</aop:config>
</beans>
Spring AOP