java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference

28.4k views Asked by At

After a long search and no answer to my case, here I am. Trying to deploy a "Struts 2 + Maven + Spring" WAR project into Wildfly 11, using Eclipse Oxigen's default to all.

The stack is as it follows:

15:04:27,325 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) WFLYSRV0027: Starting deployment of "MSDB.war" (runtime-name: "MSDB.war")
15:04:30,148 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-4) MSC000001: Failed to start service jboss.deployment.unit."MSDB.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."MSDB.war".POST_MODULE: WFLYSRV0153: Failed to process phase POST_MODULE of deployment "MSDB.war"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:172)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:2032)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1955)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class org.springframework.web.context.ContextLoader with ClassLoader ModuleClassLoader for Module "deployment.MSDB.war" from Service Module Loader
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:78)
    at org.jboss.as.ee.metadata.MethodAnnotationAggregator.runtimeAnnotationInformation(MethodAnnotationAggregator.java:57)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.handleAnnotations(InterceptorAnnotationProcessor.java:106)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:91)
    at org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:76)
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:165)
    ... 5 more
Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference;
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Unknown Source)
    at java.lang.Class.getDeclaredFields(Unknown Source)
    at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:72)
    at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70)
    ... 10 more
Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference from [Module "deployment.MSDB.war" from Service Module Loader]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:412)
    at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:400)
    at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
    ... 15 more

15:04:30,150 ERROR [org.jboss.as.controller.management-operation] (External Management Request Threads -- 4) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "MSDB.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"MSDB.war\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"MSDB.war\"
    Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class org.springframework.web.context.ContextLoader with ClassLoader ModuleClassLoader for Module \"deployment.MSDB.war\" from Service Module Loader
    Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference;
    Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference from [Module \"deployment.MSDB.war\" from Service Module Loader]"}}
15:04:30,151 ERROR [org.jboss.as.server] (External Management Request Threads -- 4) WFLYSRV0021: Deploy of deployment "MSDB.war" was rolled back with the following failure message: 
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"MSDB.war\".POST_MODULE" => "WFLYSRV0153: Failed to process phase POST_MODULE of deployment \"MSDB.war\"
    Caused by: java.lang.RuntimeException: WFLYSRV0177: Error getting reflective information for class org.springframework.web.context.ContextLoader with ClassLoader ModuleClassLoader for Module \"deployment.MSDB.war\" from Service Module Loader
    Caused by: java.lang.NoClassDefFoundError: Lorg/springframework/beans/factory/access/BeanFactoryReference;
    Caused by: java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference from [Module \"deployment.MSDB.war\" from Service Module Loader]"}}
15:04:30,268 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0028: Stopped deployment MSDB.war (runtime-name: MSDB.war) in 116ms

pom.xml is currently like this (after inserting a lot of extra dependencies, from tries from previous searches on the web):

<project xmlns="http://maven.apache.org/POM/4.0.0" mlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>SBMC</groupId>
<artifactId>MSDB</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>MSDB</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-core</artifactId>
        <version>2.3.34</version>
    </dependency>

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-spring-plugin</artifactId>
        <version>2.3.16.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.0.0.RELEASE</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>5.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-expression</artifactId>
        <version>5.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>5.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>5.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.3.Final</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>

</dependencies>

<build>
    <finalName>MSDB</finalName>
    <plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>5.0</version>
    </plugin>
    <!-- <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
    </plugin> -->
</plugins>
</build>
</project>

I searched a lot, but nothing I found solved my issue.

6

There are 6 answers

0
Eder Armando Anillo Lora On

I did many fixes vulnerabilities in my project, and I found this problerm too. I was comparing the versions, and the spring-web version 5.3.18, still calling the class org.springframework.beans.factory.access.BeanFactoryReference from org.springframework.web.context.ContextLoaderListener. The called to taht class shouldn't exist for that version. So I upgraded the spring libraries to 5.3.19 , without modify the spring-security-saml2-core, and the project works. This is a part of my gradle file::

implementation group: 'org.springframework.security', name: 'spring-security-web', version: '5.6.3'
implementation group: 'org.springframework.security', name: 'spring-security-core', version: '5.6.3'
implementation group: 'org.springframework', name: 'spring-web', version: '5.3.19'
compile group: 'org.springframework.security.extensions', name: 'spring-security-saml2-core', version: '1.0.10.RELEASE'
0
Se Song On

Your problem is here

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.3.Final</version>
</dependency>

You're using Spring 5, so you should update your hibernate to version 5 too, I use hibernate 5.0.0.Final.

2
Srikanth Anusuri On

You may have an issue with the spring-core dependency here. Unless you have spring-core in your classpath I would recommend changing the dependency scope to default (or jar) instead of runtime.

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>5.0.0.RELEASE</version>
</dependency>
0
justMe On

I had this issue and I was trying to deploy war file to tomcat 8, in my case one of the library I was using had a dependency on spring-context which brought in version 4.3.3, in this version there is class

public class ContextBeanFactoryReference implements BeanFactoryReference

As you found out BeanFactoryReference doesn't exist in version 5.

I can see you already got spring-context version 5, just double check your dependencies and make sure there is only spring version 5 and none others.

if there is any others brought in by some other libraries you could exclude them by using

<exclusions>
 <exclusion>
   <groupId>org.springframework</groupId>
   <artifactId>spring-context</artifactId>
 </exclusion>
</exclusions>

That sorted my problem and it feels yours is something similar.

0
Alireza Fattahi On

It is possible that you have some spring frame works libraries indirectly added to your project. So you may have for example spring-tx-4.3.11.RELEASE or spring-context-support-4.3.11.RELEASE or ... in your final class path.

To solve it make sure that there are no spring frame work packages with version less than 5.0.0 in your class path.

Some of the spring framework groups which must have version 5.0.0 are:

  1. spring-context
  2. spring-test
  3. spring-cores
  4. spring-beans
  5. spring-web
  6. spring-webmvc
  7. spring-oxm
  8. spring-jms
  9. spring-jdbc

I used eclipse pom viewer, you can see which packages include version of spring framework by using Dependency Hierarchy tab. Then you can exclude them.

For example for struts you must do below:

    <dependency>
        <groupId>org.apache.struts</groupId>
        <artifactId>struts2-junit-plugin</artifactId>
        <version>${struts2.version}</version>
        <exclusions>
            <exclusion>
                <artifactId>spring-context</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <artifactId>spring-core</artifactId>
                <groupId>org.springframework</groupId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

The exclusion may be needed for other frameworks too, even spring security or spring-ws

0
bkiselka On

If you have this error when using

    <dependency>
        <groupId>org.springframework.security.extensions</groupId>
        <artifactId>spring-security-saml2-core</artifactId>
        <version>1.0.0.RELEASE</version>
    </dependency>

and upgrading to Spring Framework 5: upgrade to version 1.0.3-RELEASE!

See https://github.com/spring-projects/spring-security-saml/issues/211 for details.