spring-context-5.2.8.RELEASE.jar
spring-expression-5.2.8.RELEASE.jar
spring-context-5.2.8.RELEASE-sources.jar
commons-logging-1.1.1.jar
spring-core-5.2.8.RELEASE.jar
spring-beans-5.2.8.RELEASE.jar
spring-aspects-5.2.8.RELEASE.jar
spring-aop-5.2.8.RELEASE.jar
(使用@Aspect注解需要导入)
@Service public class UserService { public void add() { System.out.println("UserService add..."); System.out.println(1/0); } }
@Component @Aspect public class UserServiceProxy { @After(value = "execution(* com.orz.spring.aop.UserService.add(..))") public void logAfter() { System.out.println("After"); } @AfterReturning(value = "execution(* com.orz.spring.aop.UserService.add(..))") public void logAfterReturnning() { System.out.println("AfterReturnning"); } }
<context:component-scan base-package="com.orz.spring"/> <aop:aspectj-autoproxy/>
@Test public void test1() { ApplicationContext applicationContext=new ClassPathXmlApplicationContext("bean.xml"); UserService userService = applicationContext.getBean("userService", UserService.class); userService.add(); }
UserService add... After java.lang.ArithmeticException: / by zero
原文:https://www.cnblogs.com/orzjiangxiaoyu/p/13862300.html