ClassCastException for configuration CGLIB proxy and org.springframework.cglib.proxy.Factory after upgrade Spring to 6.0.9 and Spring Boot to 3.0.6

huangapple go评论95阅读模式
英文:

ClassCastException for configuration CGLIB proxy and org.springframework.cglib.proxy.Factory after upgrade Spring to 6.0.9 and Spring Boot to 3.0.6

问题

在我们的项目中,在将SpringBoot从3.0.4升级到3.0.9之后,我们的一些测试开始失败了

Caused by: org.springframework.aop.framework.AopConfigException: 非预期的AOP异常
在app//org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:222) 
在app//org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:158) 
在app//org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) 
在app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildProxy(AbstractAutoProxyCreator.java:517) 
在app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:464) 
在app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:369) 
在app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:318) 
在app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434) 
在app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773) 
在app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598) 
... 80 more 
Caused by: java.lang.ClassCastException: 类our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0无法转换为org.springframework.cglib.proxy.Factory(our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0和org.springframework.cglib.proxy.Factory在' app '加载程序的未命名模块中)
在org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:91) 
在org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:213) 
... 89 more 

这不仅仅限于our.project.RepositoryConfiguration$LiquibaseConfiguration。当我禁用此配置时,下一个配置会发生类似的异常。

另一件奇怪的事情是,只有在调用单个测试类或者首先执行此类时,测试才会通过。否则,会发生ClassCastException异常。

我们使用TestNG进行测试。

我尝试将Spring从3.0.4升级到3.0.6,将Spring Boot从3.0.4升级到3.0.6,并期望我们当前的所有测试都能通过。但是对于我们约2000个测试中的34个测试,会发生java.lang.ClassCastException: 类our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0无法转换为org.springframework.cglib.proxy.Factory(our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0和org.springframework.cglib.proxy.Factory在' app '加载程序的未命名模块中)异常。

英文:

In our project, after upgrade the SpringBoot from 3.0.4 to 3.0.9, several of our tests started to fail on

Caused by: org.springframework.aop.framework.AopConfigException: Unexpected AOP exception
	at app//org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:222)
	at app//org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:158)
	at app//org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
	at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.buildProxy(AbstractAutoProxyCreator.java:517)
	at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:464)
	at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:369)
	at app//org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:318)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:434)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1773)
	at app//org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:598)
	... 80 more
Caused by: java.lang.ClassCastException: class our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 cannot be cast to class org.springframework.cglib.proxy.Factory (our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 and org.springframework.cglib.proxy.Factory are in unnamed module of loader 'app')
	at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:91)
	at org.springframework.aop.framework.CglibAopProxy.buildProxy(CglibAopProxy.java:213)
	... 89 more

It's not bounded just to the our.project.RepositoryConfiguration$LiquibaseConfiguration. When I disable this configuration, then similar exception occurs on next configuration.

Another weird thing is that the test passes if only the single test class is called or if this class is executed first. Otherwise the ClassCastException ocurs.

We use TestNG for testing.

I tried to upgrade Spring to version 3.0.6 from 3.0.4 and Spring Boot to version 3.0.6 from 3.0.4 and I expect that all our current tests will pass. But for 34 tests of our ~ 2000 there is an exception java.lang.ClassCastException: class our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 cannot be cast to class org.springframework.cglib.proxy.Factory (our.project.RepositoryConfiguration$LiquibaseConfiguration$$SpringCGLIB$$0 and org.springframework.cglib.proxy.Factory are in unnamed module of loader 'app')

答案1

得分: 0

最终,在将近一周的调查后,我成功地确定了罪魁祸首。Solr 8.2.1 导致了这个问题。使用 Solr 8.2.0 时,它可以正常工作,但在 Solr 8.2.1 中会出现 spring 代理的类转换异常。

难以相信这与此有关。

英文:

Finally. after almost of week of investigations, I managed to isolate the sinner. Solr 8.2.1 causes this issue. With Solr 8.2.0 it works with Solr 8.2.1 there is class cast exception for spring proxies.

Hard to believe that this is related.

huangapple
  • 本文由 发表于 2023年6月1日 19:09:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381260.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定