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.
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();
}
}