Can AOP proxying be prevented for certain classes?
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.
Any ideas appreciated!
I think that there is not a simple way to do it.
I see two options:
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)Other (more generic) way is overriding the
shouldSkip()
method ofAbstractAutoProxyCreator
and set your ownAutoproxyCreator
in aBeanFactoryPostProcessor
using thesetBeanClassName()
method on the bean definition registered by Spring Security, ieAopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME
. For this approach you need to take care about what implementation ofAutoProxyCreator
are you finally using (InfrastructureAdvisorAutoProxyCreator
,AspectJAwareAdvisorAutoProxyCreator
orAnnotationAwareAspectJAutoProxyCreator
)