Java 类型 org.springframework.context.ConfigurableApplicationContext 无法解析。它是从所需的 .class 文件间接引用的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40086257/
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
The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
提问by
I am following the tutorial at spring.ioto build a spring app using spring boot.
我正在按照spring.io上的教程使用 Spring Boot 构建一个 spring 应用程序。
I can get the program to run perfectly on one computer. When I try on a different computer I get the following error
我可以让程序在一台计算机上完美运行。当我在另一台计算机上尝试时,出现以下错误
The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files
类型 org.springframework.context.ConfigurableApplicationContext 无法解析。它是从所需的 .class 文件间接引用的
I have tried deleting and adding my JRE Systems Library (JDK 1.8), as well as cleaning and updating the project using maven, and even deleting and re-importing the entire project. All of these methods have shown no success.
我尝试删除和添加我的 JRE 系统库(JDK 1.8),以及使用 maven 清理和更新项目,甚至删除和重新导入整个项目。所有这些方法都没有成功。
My pom file is
我的pom文件是
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns: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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
</parent>
<groupId>test.api</groupId>
<artifactId>api.test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>api.test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<finalName>api.test</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
The class that is giving me the error is the HelloWorldConfiguration.java class
给我错误的类是 HelloWorldConfiguration.java 类
package hello;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class HelloWorldConfiguration {
public static void main(String[] args) {
SpringApplication.run(HelloWorldConfiguration.class, args);
}
}
Any help would be greatly appreciated. Thank you.
任何帮助将不胜感激。谢谢你。
回答by Stephane Nicoll
Your Maven cache is corrupted on the second machine. The JAR can't be opened, that's why you get this exception.
您的 Maven 缓存在第二台机器上已损坏。无法打开 JAR,这就是您收到此异常的原因。
You can fix that by running this command on the second machine for that project:
您可以通过在该项目的第二台机器上运行此命令来解决此问题:
mvn dependency:purge-local-repository
If that doesn't work, try remove your local repo on that machine (~/.m2/repository/org/springframework
) and run mvn package
again.
如果这不起作用,请尝试删除该机器上的本地存储库 ( ~/.m2/repository/org/springframework
) 并mvn package
再次运行。
回答by Deepak Soni
I had the same problem. I resolved this my deleting the local repository directory of Maven (.m2) on your local computer. It resolved the problem for me.
我有同样的问题。我解决了这个问题,我删除了本地计算机上 Maven (.m2) 的本地存储库目录。它为我解决了问题。
回答by xpioneer
I also faced the same issue before. Some dependency corruption might have occurred. You can purge and re-resolve the dependencies. For that :
我之前也遇到过同样的问题。可能发生了一些依赖关系损坏。您可以清除并重新解析依赖项。为了那个原因 :
- go to the project location where the pom.xml is present.
open a command prompt there and enter the command below :
mvn dependency:purge-local-repository -DreResolve=true
- 转到存在 pom.xml 的项目位置。
在那里打开命令提示符并输入以下命令:
mvn 依赖项:purge-local-repository -DreResolve=true
回答by Pankaj Sharma
I had the same issue and I followed these steps to fix it:
我遇到了同样的问题,我按照以下步骤来解决它:
1.Close Eclipse
1.关闭Eclipse
2.Remove all files inside the repository folder .m2/repository
2.删除存储库文件夹中的所有文件.m2/repository
3.reopen Eclipse and update your Maven project
3.重新打开 Eclipse 并更新您的 Maven 项目
回答by krishna Tyagi
this conflict occurs, because some of your dependencies have corrupted.follow this:-> for removing this conflict just go in to your .m2 folder open repository and delete all the files from that folder. and now open your project go in debug do maven clean and after cleaning and all downloading just update your maven projet. and your conflict will have been going to resolve.
发生此冲突,因为您的某些依赖项已损坏。请按照以下步骤操作:-> 要消除此冲突,只需进入 .m2 文件夹打开存储库并删除该文件夹中的所有文件。现在打开你的项目,在 debug do maven clean 和清理和所有下载后只更新你的 maven projet。你的冲突将会得到解决。
回答by Naresh Reddy Kallamadi
I too have same problem, I resolved by removing .m2/repository/org folder,later did maven updated form STS.
我也有同样的问题,我通过删除 .m2/repository/org 文件夹解决了,后来 maven 更新了 STS。
回答by Barun
- Find out the version of spring-context your project uses:
- 找出您的项目使用的 spring-context 版本:
(in Eclipse : Project Explorer -> [your project] -> Maven Dependencies)
(在 Eclipse 中:项目资源管理器 -> [你的项目] -> Maven 依赖项)
or
或者
mvn dependency:tree
Lists all dependencies for your project
列出项目的所有依赖项
- Delete the folder
org/springframework/spring-context/5.0.9.RELEASE
from your maven repository.m2/repository
. Assuming5.0.9.RELEASE
is the spring-context release version.
org/springframework/spring-context/5.0.9.RELEASE
从您的 Maven 存储库中删除该文件夹.m2/repository
。假设5.0.9.RELEASE
是 spring-context 发布版本。
回答by abhishek ojha
I also faced the same issue and to resolve this I downloaded the jar and added as an external jar. Here is the download link: http://www.java2s.com/Code/Jar/o/Downloadorgspringframeworkcontextjar.htm
我也遇到了同样的问题,为了解决这个问题,我下载了 jar 并添加为外部 jar。这是下载链接:http: //www.java2s.com/Code/Jar/o/Downloadorgspringframeworkcontextjar.htm