0

My application was recently upgraded from Spring 3.x to Spring 4.x (via moving our app to Spring-boot, latest version)

We have some AOP in place that look like this and worked fine prior to this upgrade: (cglib was being used to create the proxies)

<bean id="myproxycreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="proxyTargetClass" value="true"/>
    <property name="interceptorNames">
        <list>
            <value>myInterceptor</value>
        </list>
    </property>
    <property name="beanNames">
        <list>
            <value>myBean</value>
        </list>
    </property>
</bean>

After embedded our app within a spring-boot started app, we are now getting these kinds of errors on startup (note NONE of these classes being proxied are 'final') but it appears that despite proxyTargetClass being = TRUE, something in Spring is trying to do a "proxy of a proxy??"

If we change proxyTargetClass=FALSE, I guess it then uses JDK based proxies? However when we do that, our AOP interceptors are no longer being called... confused as to how to triage this issue.

Any help appreciated.

Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.sun.proxy.$Proxy90]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy90
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:212)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:109)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:447)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:333)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 105 common frames omitted
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class com.sun.proxy.$Proxy90
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
at org.springframework.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
at org.springframework.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:56)
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:202)
... 112 common frames omitted
bitsofinfo
  • 994
  • 3
  • 16
  • 34
  • 1
    Spring boot already adds a auto proxy creator and you adding another will lead to proxying a proxy. Just ditch that part of the configuration and use an `@Aspect` with a `bean` point cut to apply your interceptor. – M. Deinum Jul 24 '15 at 11:36
  • Ditch what exactly? My entire XML config? I'd like to keep the configuration of this externalized. – bitsofinfo Jul 24 '15 at 12:02
  • Define externalized here, it is just configuration regardless if you put it in xml, java or properties files. But you shouldn't add another auto proxy creator as that will lead to proxying proxies hence you should drop that `BeanNameAutoProxyCreator`. – M. Deinum Jul 24 '15 at 12:05
  • Well I'd prefer for this code which works already just to work as it is. Is there anyway I can just disable the auto-proxying that spring-boot is doing that is causing this double proxy? – bitsofinfo Jul 24 '15 at 12:10
  • Maybe exclude AopAutoConfiguration.class? – bitsofinfo Jul 24 '15 at 12:12
  • Well you could with the risk other defaults might break. It is imho easier to write an aspect with the bean point cut to replace this piece of configuration. – M. Deinum Jul 24 '15 at 12:14
  • Excluding, AopAutoConfiguration does fix my issue and CGlib is used again w/ no double proxies... but yes, I guess now I don't know what else is busted in the spring-boot internals (which we are not using much of yet now) – bitsofinfo Jul 24 '15 at 12:19
  • The way I read these docs, it appears this won't cause any harm http://docs.spring.io/spring-framework/docs/4.1.7.RELEASE/javadoc-api/org/springframework/context/annotation/EnableAspectJAutoProxy.html?is-external=true http://docs.spring.io/spring-boot/docs/1.2.5.RELEASE/api/org/springframework/boot/autoconfigure/aop/AopAutoConfiguration.html – bitsofinfo Jul 24 '15 at 12:22
  • Unless you want to use other aspects / AOP things then probably not as it is very restricting. You are trying to hold on to old ways but still use the newest technologies and don't want to upgrade the ways. Not that it won't work but it will limit you severely in your future endeavors especially when using Spring Boot... – M. Deinum Jul 24 '15 at 12:25
  • probably adding `spring.aop.auto=false` to the application.properties will do the same trick. – M. Deinum Jul 24 '15 at 12:29
  • I understand your point, however this is a phased move of this older app to spring boot, Once thing at a time, make sure things work as-is, then start implementing changes, which I am sure you can understand. Thanks for your help ! – bitsofinfo Jul 24 '15 at 12:33
  • I do understand however my experience is that it rarely happens as it works so why change or we don't have time for that. – M. Deinum Jul 24 '15 at 12:38
  • You could wait for Spring Boot 1.3, which will use Spring Framework 4.2, where this problem (proxy of a proxy) seems to have been fixed. Or, you could use Spring 4.2 right away in your Maven POM (or Gradle) file. – manish Aug 01 '15 at 09:16

0 Answers0