spring - 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);
}
}
解决方案
推荐阅读
- python-2.7 - python 2:将字符串变量转换为与arcpy中的sql字符串兼容的格式
- python - 在数据框中的 json 记录中查找空值
- image - 使用平均滤波器的部分模糊图像
- python - 如何从函数返回变量和值以供将来使用?
- python - Arduino Python串行通信错误
- javascript - 如何将小时数添加到 unix 时间戳毫秒?
- r - 尝试在 R 中使用 read_xml 函数并获得 0 列表时出现问题?
- json - 使用 jQ 将 JSON 字典转换为 JSON 行
- json - 来自 JSON 的 Xcode 12 和 SVG 与 swift
- html - 我将如何使我的背景颜色保持在我的包装器的范围内并保持响应性?