eclipse org.springframework.context.ConfigurableApplicationContext 类型无法解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38512340/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 23:14:51  来源:igfitidea点击:

The type org.springframework.context.ConfigurableApplicationContext cannot be resolved

eclipsespring-bootspring-tool-suite

提问by raji

I am getting the following error, when i tried to create my first application in Spring Tool Suite:

当我尝试在 Spring Tool Suite 中创建我的第一个应用程序时,出现以下错误:

Multiple markers at this line - The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is indirectly referenced from required .class files - The method run(Object, String...) from thae type SpringApplication refers to the missing type ConfigurableApplicationContext

此行有多个标记 - 无法解析类型 org.springframework.context.ConfigurableApplicationContext。它是从所需的 .class 文件间接引用的 - 来自 SpringApplication 类型的 run(Object, String...) 方法指的是缺少的类型 ConfigurableApplicationContext

This is the following pom.xml

这是下面的 pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.welcome</groupId>
        <artifactId>demo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>jar</packaging>

        <name>welcome</name>
        <description>Demo project for Spring Boot</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.3.6.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
        </properties>



        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>
        </dependencies>

        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>



    This is the Controller Used


    package com.welcome.demo;

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.SpringBootApplication;


    @SpringBootApplication
    @EnableAutoConfiguration
    public class WelcomeApplication {

        public static void main(String[] args)throws Exception {
            SpringApplication.run(WelcomeApplication.class, args);
        }
    }

Can any one help in this? what is my mistake? And it is showing red exclamation mark on the project folder.

任何人都可以帮忙吗?我的错误是什么?它在项目文件夹上显示红色感叹号。

回答by bpjoshi

Your maven cache is corrupted. To resolve this problem, follow the steps below:

您的 Maven 缓存已损坏。要解决此问题,请按照以下步骤操作:

  • Go to the directory of your project on the command line.
  • Make sure your POM.xml is in the same directory as your command line
  • Run the command

    mvn dependency:purge-local-repository
    
  • If you receive build successfulmessage, means the error has been resolved.

  • If error is still there, delete your (~/.m2/repository/org/springframework) folder and run

    mvn package
    
  • 在命令行上转到您的项目目录。
  • 确保您的 POM.xml 与您的命令行在同一目录中
  • 运行命令

    mvn dependency:purge-local-repository
    
  • 如果您收到构建成功消息,则表示错误已解决。

  • 如果错误仍然存​​在,请删除您的 (~/.m2/repository/org/springframework) 文件夹并运行

    mvn package
    

It will work properly now.

现在它会正常工作。

回答by Kushal

Updated the spring-boot-starter-parent to latest version . Resolved the problem for me

将 spring-boot-starter-parent 更新到最新版本。为我解决了问题

<parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      **<version>1.3.6.RELEASE</version> // update this to latest**
      <relativePath/> <!-- lookup parent from repository -->
</parent>