防止某些类的AOP代理 [英] Prevent AOP proxying of some classes

查看:106
本文介绍了防止某些类的AOP代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以防止某些类的AOP代理?

Can AOP proxying be prevented for certain classes?

例如,当使用Spring Security中的global-method-security时.在这种情况下,我希望代理大多数带有注释的bean.但是对于某些bean,我已经在使用具有某些特殊语义的自定义代理.

For instance when using global-method-security from Spring Security. In this case I want most beans with annotations to be proxied. But for some beans I am already using a custom proxy with certain special semantics.

任何想法表示赞赏!

推荐答案

我认为没有简单的方法可以做到这一点.

I think that there is not a simple way to do it.

我看到两个选择:

  • 扩展SecuredAnnotationSecurityMetadataSource并覆盖findAttributes()方法.然后禁用secured-annotation并使用metadata-source-ref属性启用您自己的SecuredAnnotationSecurityMetadataSource. (更简单,但仅适用于Spring Security)

  • Extends SecuredAnnotationSecurityMetadataSource and override findAttributes() method. Then disable secured-annotation and enable your own SecuredAnnotationSecurityMetadataSource with the metadata-source-ref attribute. (Is simpler but work only with spring security)

其他(更通用)的方法是覆盖AbstractAutoProxyCreatorshouldSkip()方法,并在Spring Security注册的bean定义上使用setBeanClassName()方法在BeanFactoryPostProcessor中设置自己的AutoproxyCreator,即AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME.对于这种方法,您需要注意最终要使用哪种AutoProxyCreator实现(InfrastructureAdvisorAutoProxyCreatorAspectJAwareAdvisorAutoProxyCreatorAnnotationAwareAspectJAutoProxyCreator)

Other (more generic) way is overriding the shouldSkip() method of AbstractAutoProxyCreator and set your own AutoproxyCreator in a BeanFactoryPostProcessor using the setBeanClassName() method on the bean definition registered by Spring Security, ie AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME. For this approach you need to take care about what implementation of AutoProxyCreator are you finally using (InfrastructureAdvisorAutoProxyCreator, AspectJAwareAdvisorAutoProxyCreator or AnnotationAwareAspectJAutoProxyCreator)

这篇关于防止某些类的AOP代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆