I am using Spring Boot, and I would like to use AspectJ with it.
The following works (of course):
@Aspect
@Component
public class RequestMappingAspect {
@Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
public void advice(JoinPoint joinPoint) {
...
}
}
However, if @Component is removed and @EnableAspectJAutoProxy is added, the following does not work.
@SpringBootApplication
@EnableSwagger2
@EnableAspectJAutoProxy
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
How to enable AspectJ auto proxy correctly?
@EnableAspectJAutoProxyyou do not use AspectJ, but proxy-based Spring AOP. But probably that is what you want anyway. - kriegaex@Componentno instance of the aspect will be created, hence no aspects available so nothing to use. You need both@Componentand@Aspectto make it work (or define the aspect as a@Beanmethod). Either way an instance of the aspect has to be there to make it work. - M. Deinum