Spring Boot应用程序无法解析org.springframework.boot包 [英] Spring Boot application can't resolve the org.springframework.boot package

查看:1222
本文介绍了Spring Boot应用程序无法解析org.springframework.boot包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Spring Initializer 设置了一个spring boot项目,我多次尝试创建一个新项目或者使用依赖项,一切似乎都已到位。

I have set up a spring boot project using the Spring Initializer, I tried several times to create a new project or play with the dependencies, everything seems to be in place.

我正在使用STS(Spring Tool Suite)并显示有关从<$ c $导入的错误c> org.springframework.boot 包。运行应用程序会抛出异常:

I am using STS(Spring Tool Suite) and it shows errors about the imports from theorg.springframework.boot package. Running the application throws an exception:


线程main中的异常java.lang.Error:未解析的编译
问题:SpringApplication无法解决。

Exception in thread "main" java.lang.Error: Unresolved compilation problem: SpringApplication cannot be resolved.

com.example.DemoApplication:

com.example.DemoApplication:

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

@SpringBootApplication
public class DemoApplication {

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

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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

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

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

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <start-class>com.example.DemoApplication</start-class>
    </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>
    </dependencies>

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


</project>

我正在使用带有STS的Java 1.8。

I am using Java 1.8 with STS.

推荐答案

更改spring boot parent的版本

change the version of spring boot parent

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
 </parent>

这篇关于Spring Boot应用程序无法解析org.springframework.boot包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆