Search code examples
javaspringgradlebuild

Runtime java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference after Spring upgrade from 4 to 5


I upgraded my Java application from Spring 4 to Spring 5 and i am getting java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference error while running on tomcat server. followed by java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference

Please help me to fix this issue..

Below are dependencies in my build.gradle file

compile 'org.springframework:spring-context-support:5.2.11.RELEASE'
compile 'org.springframework:spring-webmvc:5.2.11.RELEASE'
    
compile 'org.springframework.security:spring-security-config:5.2.8.RELEASE'
compile 'org.springframework.security:spring-security-web:5.2.8.RELEASE'
compile 'org.springframework.security:spring-security-ldap:5.2.8.RELEASE'

compile 'org.springframework.integration:spring-integration-sftp:5.2.11.RELEASE'

compile 'org.springframework.ws:spring-ws-core:3.0.9.RELEASE'
    
compile 'com.thoughtworks.xstream:xstream:1.4.14'

compile 'com.fasterxml.jackson.core:jackson-databind:2.9.10'

compile 'wsdl4j:wsdl4j:1.6.3'
compile 'commons-discovery:commons-discovery:0.2'
compile 'javax.xml:jaxrpc-api:1.1'
compile 'com.google.guava:guava:24.1.1-android'
compile('org.apache.poi:poi-ooxml:4.1.2') {
    exclude group: 'stax', module: 'stax-api'
}
compile 'javax.validation:validation-api:1.1.0.Final'
compile 'org.hibernate:hibernate-validator:5.1.3.Final'

compile 'org.apache.httpcomponents:httpclient:4.5'
compile 'commons-fileupload:commons-fileupload:1.4'

compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.13.3'

compile 'com.lmax:disruptor:3.3.4'

compile 'org.codehaus.woodstox:woodstox-core-asl:4.4.1'

compile 'org.apache.commons:commons-csv:1.2'

providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
providedCompile 'javax.servlet.jsp.jstl:jstl-api:1.2'
providedCompile 'javax.servlet:jstl:1.2'
providedCompile 'org.glassfish.web:jstl-impl:1.2'
providedCompile 'com.microsoft.sqlserver:sqljdbc4:2.0'
providedCompile 'javax.xml.bind:jaxb-api:2.2.12'

testCompile 'org.springframework:spring-test:5.2.11.RELEASE'
    
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-all:1.9.5'
testCompile 'foo-commonj:foo-commonj:1.1.0'
testCompile 'commonj-twm:commonj-twm:1.1.0'


integrationTestCompile sourceSets.main.output
integrationTestCompile configurations.testCompile
integrationTestCompile sourceSets.test.output
integrationTestRuntime configurations.testRuntime

Please let me know if more information required from my side.


Solution

  • I resolved it by myself. I cleaned tomcat history by tomcat -> clean I did gradle refresh, ran again on tomcat server and issue resolved.

    Tomcat was taking application's old build. In previous build I had spring-ws-core:2.x.RELEASE which was bringing spring-beans.4.x.jar and it is incompatible with other spring 5 jars. so root cause was incompatible jars and then tomcat cache build.