【问题标题】:Error: java: package org.springframework.boot does not exist错误:java:包 org.springframework.boot 不存在
【发布时间】:2020-05-15 04:06:52
【问题描述】:

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

我收到以下错误:

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

这是我的 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>

我试过了:

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

还有其他想法吗?

【问题讨论】:

标签: java spring spring-boot maven intellij-idea


【解决方案1】:

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

您可以使用a workaround,直到修复发布或downgrade to 2019.3.x version

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

或者确保path.macros.xml文件存在于&lt;IDE config&gt;/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>

&lt;path to&gt;/.m2/repository - 是本地 Maven 存储库的路径,&lt;path to IDE installation&gt; - IDE 安装主目录的路径。

【讨论】:

    【解决方案2】:

    在我的例子中已经改变了 Maven 导入 JDK 版本。 在 intellij 的最新版本中,它指向 JDK11。然后更改我的内部 JDK 版本解决了 issue

    【讨论】:

      【解决方案3】:

      我按照这些步骤成功构建了我的项目。

      1. 运行mvn clean
      2. 转到设置 -> 构建、执行、部署 -> Maven -> 存储库并更新它们。(不确定这是否必要)
      3. 通过单击 maven 选项卡上的重新加载按钮刷新您的 maven 依赖项。
      4. 去构建并点击重新构建项目。

      【讨论】:

        【解决方案4】:

        将 spring-boot-starter-web 依赖添加到你的 POM

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

        【讨论】:

        • 感谢您的回答,但我确定它与pom文件没有任何关系
        【解决方案5】:

        不需要在 pom.xml 中需要 spring-boot 依赖项

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

        【讨论】:

        • 谢谢你的回答,但它仍然给我错误
        【解决方案6】:

        好吧,我只需重新启动具有所有必需依赖项和 JDK 设置的笔记本电脑即可解决此问题。

        【讨论】:

          猜你喜欢
          • 2023-02-14
          • 1970-01-01
          • 2019-05-21
          • 2019-01-11
          • 2018-07-28
          • 1970-01-01
          • 2019-11-08
          • 2021-07-06
          • 2011-09-16
          相关资源
          最近更新 更多