Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring AOP without XML

Tags:

java

spring

xml

aop

I am trying to set up Spring AOP without any XML and wonder how to enable auto-proxying this way.

Defining an AutoProxyCreator-bean works, but isn't there an easier way?

This is what my @Configuration looks like:

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

All other beans are scanned in by AnnotationConfigApplicationContext.

like image 817
CKuck Avatar asked Dec 12 '11 11:12

CKuck


1 Answers

Spring 3.0.x doesn't provide easy ways to replace XML namespace extensions (such as <aop:aspectj-autoproxy>) in @Configuration.

An upcoming Spring 3.1 will support special annotations for this purpose, such as @EnableAspectJAutoProxy.

like image 139
axtavt Avatar answered Oct 03 '22 00:10

axtavt