How to enable <aop:aspectj-autoproxy> with java-based annotations How to enable <aop:aspectj-autoproxy> with java-based annotations java java

How to enable <aop:aspectj-autoproxy> with java-based annotations


Did you create an aspect bean in the same @Configuration class?Here's what the docs suggest:

 @Configuration @EnableAspectJAutoProxy public class AppConfig {     @Bean     public FooService fooService() {         return new FooService();     }     @Bean // the Aspect itself must also be a Bean     public MyAspect myAspect() {         return new MyAspect();     } }


I used the accepted answer solution but I had unexpected problems and never understand untill to add this parameter to configuration.

@EnableAspectJAutoProxy(proxyTargetClass = true)

If you use annotation into @Controller you'll need to configure in this way

remember if you have java 8 you need to use a version of AspectJ greater than 1.8.X

@Configuration@EnableAspectJAutoProxy(proxyTargetClass = true)public class AppConfig {    @Bean    public AccessLoggerAspect accessLoggerAspect() {        return new AccessLoggerAspect();    }}