没有 XML 的 Spring AOP
我正在尝试在没有任何 XML 的情况下设置 Spring AOP,并且想知道如何以这种方式启用自动代理。
定义一个 AutoProxyCreator-bean 是可行的,但是有没有更简单的方法呢?
这就是我的 @Configuration 的样子:
@Configuration
public class Context {
@Bean
public AnnotationAwareAspectJAutoProxyCreator annotationAwareAspectJAutoProxyCreator() {
return new AnnotationAwareAspectJAutoProxyCreator();
};
...
}
所有其他 bean 都由 AnnotationConfigApplicationContext 扫描。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Spring 3.0.x 没有提供简单的方法来替换
@Configuration
中的 XML 命名空间扩展(例如
)。即将推出的 Spring 3.1 将支持用于此目的的特殊注释,例如
@EnableAspectJAutoProxy
。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
.最后,我找到了一种美观的方式来添加 AnnotationAwareAspectJAutoProxyCreator:
Finally I found an aesthetically pleasing way to add the
AnnotationAwareAspectJAutoProxyCreator
: