java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46611786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: org.springframework.beans.factory.access.BeanFactoryReference
提问by JokerPW
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.
经过长时间的搜索,我的案子没有得到答复,我来了。尝试将“Struts 2 + Maven + Spring”WAR 项目部署到 Wildfly 11,使用 Eclipse Oxigen 的默认设置。
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):
pom.xml 目前是这样的(在插入了很多额外的依赖之后,来自之前在网络上搜索的尝试):
<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.
我搜索了很多,但没有找到解决我的问题。
回答by Srikanth Anusuri
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.
您可能对此处的 spring-core 依赖项有问题。除非您的类路径中有 spring-core,否则我建议将依赖范围更改为默认(或 jar)而不是运行时。
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.0.RELEASE</version>
</dependency>
回答by justMe
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
我遇到了这个问题,我试图将 war 文件部署到 tomcat 8,在我的情况下,我使用的库之一依赖于引入了 4.3.3 版的 spring-context,在这个版本中有类
public class ContextBeanFactoryReference implements BeanFactoryReference
As you found out BeanFactoryReference
doesn't exist in version 5.
正如您发现的那样BeanFactoryReference
,版本 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.
我可以看到您已经获得了 spring-context 版本 5,只需仔细检查您的依赖项并确保只有 spring 版本 5 而没有其他版本。
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.
这解决了我的问题,感觉你的问题类似。
回答by Alireza Fattahi
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.
您可能indirectly
在项目中添加了一些弹簧框架库。因此,您可能在最终课程路径中有例如spring-tx-4.3.11.RELEASE
或spring-context-support-4.3.11.RELEASE
或...。
To solve it make sure that there are no spring frame work packages with version less than 5.0.0
in your class path.
要解决它,请确保没有版本低于5.0.0
您的类路径的spring 框架工作包。
Some of the spring framework groups which must have version 5.0.0 are:
一些必须具有 5.0.0 版本的 spring 框架组是:
- spring-context
- spring-test
- spring-cores
- spring-beans
- spring-web
- spring-webmvc
- spring-oxm
- spring-jms
- spring-jdbc
- 弹簧上下文
- 弹簧测试
- 弹簧芯
- 春豆
- 弹簧网
- 弹簧-webmvc
- spring-oxm
- 弹簧-jms
- 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.
我使用了 eclipse pom 查看器,您可以使用Dependency Hierarchy
选项卡查看哪些包包含 spring 框架的版本。然后你可以排除它们。
For example for struts you must do below:
例如对于 struts,您必须执行以下操作:
<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
在exclusion
可能需要的其他框架也一样,甚至spring security
或spring-ws
回答by Se Song
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
.
您正在使用 Spring 5,因此您也应该将 hibernate 更新到版本 5,我使用 hibernate 5.0.0.Final
。
回答by bkiselka
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!
并升级到 Spring Framework 5:升级到1.0.3-RELEASE版本!
See https://github.com/spring-projects/spring-security-saml/issues/211for details.
有关详细信息,请参阅https://github.com/spring-projects/spring-security-saml/issues/211。