I am trying to set up Spring AOP without any XML. I'd like to enable <aop:aspectj-autoproxy>
in a class which is annotated with @Configuration
.
This is the way it would be defined in an XML-file:
<aop:aspectj-autoproxy> <aop:include name="msgHandlingAspect" /> </aop:aspectj-autoproxy>
I tried to annotate my class with @Configuration
and @EnableAspectJAutoProxy
but nothing happened.
To enable @AspectJ, spring AOP provides @EnableAspectJAutoProxy annotation which will be annotated in java configuration. To work with spring AOP and @AspectJ support, we need to create a class annotated with @Aspect annotation.
@AspectJAutoProxy. Fashioned after Spring XML's <aop:aspectj-autoproxy> , @AspectJAutoProxy detects any @Aspect beans and generates proxies as appropriate to weave the advice methods in those aspects against other beans in the container.
Which tag informs the spring container about the use of AspectJ annotation? Explanation: To enable AspectJ annotation support in the Spring IoC container, you only have to define an empty XML element aop:aspectj-autoproxy in your bean configuration file.
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(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With