首页 > 解决方案 > SpringBootBackendApplication.java:3:错误:包 org.springframework.boot 不存在

问题描述

尝试运行 SpringBoot 应用程序时,出现以下错误:

SpringBootBackendApplication.java:3: error: package org.springframework.boot does not exist
import org.springframework.boot.SpringApplication;
                              ^
SpringBootBackendApplication.java:4: error: package org.springframework.boot.autoconfigure does not exist
import org.springframework.boot.autoconfigure.SpringBootApplication;
                                           ^
SpringBootBackendApplication.java:6: error: cannot find symbol
@SpringBootApplication
 ^
  symbol: class SpringBootApplication

这也发生在我的另一个项目中。该项目是否必须使用 Maven 运行?如果没有,什么可能导致这样的错误?代码甚至应该在其当前状态下是可执行的吗?

我的 Pom 文件:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.ourlibrary</groupId>
    <artifactId>spring-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot-backend</name>
    <description>Our Library </description>

    <properties>
        <java.version>11</java.version>
    </properties>
    <properties>
        <start-class>com.ourlibrary.springboot.Application</start-class>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </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>

我的主要方法:

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

@SpringBootApplication

public class SpringBootBackendApplication {

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

}

标签: springspring-boot

解决方案


推荐阅读