Spring AOP without XML

I am trying to configure Spring AOP without any XML and am wondering how to enable auto-proxing this way.

AutoProxyCreatorbean definition works, but is there an easier way?

Here is what my @Configuration looks like:

@Configuration public class Context { @Bean public AnnotationAwareAspectJAutoProxyCreator annotationAwareAspectJAutoProxyCreator() { return new AnnotationAwareAspectJAutoProxyCreator(); }; ... } 

All other beans are scanned by AnnotationConfigApplicationContext .

+6
source share
2 answers

Spring 3.0.x does not provide easy ways to replace XML namespace extensions (e.g. <aop:aspectj-autoproxy> ) with @Configuration .

The upcoming Spring 3.1 will support custom annotations for this purpose, such as @EnableAspectJAutoProxy .

+7
source

Finally, I found an aesthetically pleasing way to add AnnotationAwareAspectJAutoProxyCreator :

 AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.register(AnnotationAwareAspectJAutoProxyCreator.class); context.scan("com.myDomain"); context.refresh(); 
0
source

Source: https://habr.com/ru/post/903580/


All Articles