错误:java:包 org.springframework.boot 不存在

Neo*_*59Z 4 java spring intellij-idea maven spring-boot

我今天做了一个简单的应用程序,运行时出现了一些错误。我昨天做了另一个与这个非常相似的应用程序,它运行良好,但现在也坏了

我收到这些错误:

Error:(4, 32) java: package org.springframework.boot does not exist
Error:(5, 46) java: package org.springframework.boot.autoconfigure does not exist
Error:(6, 35) java: package org.springframework.context does not exist
Error:(9, 2) java: cannot find symbol
  symbol: class SpringBootApplication
Error:(13, 17) java: cannot find symbol
  symbol:   class ApplicationContext
  location: class com.example.dependencyinjection.DependencyInjectionApplication
Error:(13, 42) java: cannot find symbol
  symbol:   variable SpringApplication
  location: class com.example.dependencyinjection.DependencyInjectionApplication
Error:(3, 38) java: package org.springframework.stereotype does not exist
Error:(5, 2) java: cannot find symbol
  symbol: class Controller
Run Code Online (Sandbox Code Playgroud)

这是我的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>dependency-injection</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>dependency-injection</name>
    <description>Example project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>1.2.3.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

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

</project>
Run Code Online (Sandbox Code Playgroud)

我试过了:

  • 重新导入所有 Maven 项目
  • 为所有项目生成源并更新所有文件夹
  • 使用 Spring 初始化程序创建一个新项目
  • 检查 settings.xml 的设置路径
  • 删除 .m2 文件夹
  • 使缓存无效并重新启动
  • 使用自动导入重新打开项目
  • 删除/更改导入的 VM 选项
  • 强制 Intellij 重新读取所有 Maven 依赖项
  • 确认依赖项在模块中
  • 更新 Maven 存储库
  • 许多不同的 pom.xml 配置
  • 克隆和构建一个已知有效的项目
  • 更改 Maven 的默认可执行文件
  • 完全关闭自动同步
  • 重新安装 Intellij

还有其他想法吗?

Cra*_*der 5

IntelliJ IDEA 2020.1 和 2020.1.1 版本(将在 2020.1.2 中修复)中存在一个已知错误,其中编译器找不到 Maven 依赖项,因为路径宏未正确解析。

在修复发布或降级到 2019.3.x 版本之前,您可以使用变通方法

解决方法是覆盖设置的默认设置(macOS 上的首选项)| 构建、执行、部署 | 构建工具 | 马文 | 本地存储库(将其设置为与默认值不同的其他值)。

或者确保该path.macros.xml文件存在于具有以下内容的目录中:<IDE config>/options

<application>
  <component name="PathMacrosImpl">
   <macro name="KOTLIN_BUNDLED" value="<path to IDE installation>\plugins\Kotlin\kotlinc" />
    <macro name="MAVEN_REPOSITORY" value="<path to>/.m2/repository" />
  </component>
</application>
Run Code Online (Sandbox Code Playgroud)

其中<path to>/.m2/repository- 是本地 Maven 存储库<path to IDE installation>的路径, - 是 IDE 安装主页的路径。