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

Petr Vraník

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

Petr Vraník

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Nested Proxy using cglib in spring

Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1

What's the difference between Spring CGLIB and CGLIB?

Spring AOP CGLIB proxy's field is null

What is the difference between JDK dynamic proxy and CGLib?

Spring CGLIB, transactions and private final field initialization

avoiding problems with spring cglib proxy

Autowired bean is null in CGLib proxy

Missing field annotation in cglib proxy class

Override equals on a cglib proxy

What is CGLIB in Spring Framework?

spring - forcing cglib proxies for @Autowired fields

Cannot instantiate factory class: org.springframework.boot.autoconfigure.AutoConfigurationImportFilter" when run Spring Boot application on Tomcat

Service bean failed to inject in spring cglib proxy

spring boot error org.springframework.beans.factory.BeanCreationException datasource

Spring boot multi module project with java 11 throws cannot access class org.springframework.cglib.core.ReflectUtils

why Mixing Spring AOP proxy mechanisms (CGLIB and JDKDynmic) for dependent beans does not work

Spring Neo4j CGLIB is required to process @Configuration classes

Spring Test fails: java.lang.NoClassDefFoundError: org/springframework/cglib/transform/impl/MemorySafeUndeclaredThrowableStrategy

Exception trying to change a CGLib proxy field value

Proxy settings in Spring Boot

NamedParameterJdbcTemplate and CGlib in Spring AOP

Strange behavior with Spring CGlib autowairing?

org.springframework.beans.factory.BeanCreationException in Spring boot application

Spring JDK Dynamic Proxy and CGLIB - implementation details

How to generate proxy with custom field using cglib?

spring Cglib is useful but a class @Transactional don't proxy

Using LocalDate in Spring context and avoid CGLib issue

Auto login after registration Spring Boot 3/Spring security 6