防止某些类的AOP代理 [英] Prevent AOP proxying of some classes
问题描述
是否可以防止某些类的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 overridefindAttributes()
method. Then disablesecured-annotation
and enable your ownSecuredAnnotationSecurityMetadataSource
with themetadata-source-ref
attribute. (Is simpler but work only with spring security)
其他(更通用)的方法是覆盖AbstractAutoProxyCreator
的shouldSkip()
方法,并在Spring Security注册的bean定义上使用setBeanClassName()
方法在BeanFactoryPostProcessor
中设置自己的AutoproxyCreator
,即AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME
.对于这种方法,您需要注意最终要使用哪种AutoProxyCreator
实现(InfrastructureAdvisorAutoProxyCreator
,AspectJAwareAdvisorAutoProxyCreator
或AnnotationAwareAspectJAutoProxyCreator
)
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屋!