【问题标题】:The type org.springframework.context.ConfigurableApplicationContext cannot be resolvedorg.springframework.context.ConfigurableApplicationContext 类型无法解析
【发布时间】:2019-02-02 19:44:14
【问题描述】:

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

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

这是以下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);
        }
    }

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

【问题讨论】:

  • 很难说。但是似乎类路径中缺少一些东西。可能是 pom 的问题,或者可能是 maven/m2e 尚未正确下载所有依赖项并将它们添加到 eclipse 类路径中。尝试使用项目的“Maven”上下文菜单中的“更新项目”操作。如果这没有帮助,您可能需要在 pom 中添加一些东西以获得一些必需的依赖项。
  • 如果它对你有用,你应该点击接受bpjoshi's answer

标签: eclipse spring-boot spring-tool-suite


【解决方案1】:

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

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

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

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

    mvn package
    

它现在可以正常工作了。

【讨论】:

    【解决方案2】:

    将 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>
    

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 2016-12-15
      • 2015-10-22
      • 2013-12-14
      • 1970-01-01
      • 2017-07-19
      • 2016-09-24
      • 2014-11-07
      • 2021-08-28
      相关资源
      最近更新 更多