2

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!

Dennis Thrysøe
  • 1,791
  • 4
  • 19
  • 31

1 Answers1

1

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

I see two options:

  • 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)

  • 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)

Jose Luis Martin
  • 10,459
  • 1
  • 37
  • 38
  • Have there been any improvements/changes regarding this since the question was asked first? – ST-DDT Nov 01 '18 at 12:09