@Configuration public class AppConfig { @Bean public MyAdvice myAdvice() { return new MyAdvice(); } @Bean public MyAspect myAspect() { return new MyAspect(); } } @Aspect public class MyAspect { @Autowired private MyAdvice myAdvice; @Pointcut("execution(* com.example.service.*.*(..))") public void serviceMethods() {} @Before("serviceMethods()") public void beforeServiceMethods(JoinPoint joinPoint) { myAdvice.beforeServiceMethods(); } } @Component public class MyAdvice { public void beforeServiceMethods() { System.out.println("Before executing service methods"); } } @Service public class MyService { public void doSomething() { System.out.println("Executing doSomething method"); } }


上一篇:
下一篇:
切换中文