简体   繁体   English

无法解析符号@SpringBootApplication - IntelliJ DEA

[英]Cannot Resolve Symbol @SpringBootApplication - IntelliJ DEA

I imported a Spring Initializr build to IntelliJ and then run it as a Spring Boot build.我将 Spring Initializr 构建导入 IntelliJ,然后将其作为 Spring 引导构建运行。 The build works fine and displays in the browser but I continue to receive an error about unused imports and that @SpringBootApplication cannot be resolved.构建工作正常并显示在浏览器中,但我继续收到有关未使用导入的错误,并且无法解析 @SpringBootApplication。 I also followed these steps as well: Cannot resolve symbol SpringApplication我也遵循了这些步骤: 无法解析符号 SpringApplication

Anyone else has this issue.其他任何人都有这个问题。

package com.sts.kevthedev;

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

@SpringBootApplication
public class KevthedevApplication {

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

Try it:试试看:
File -> Invalidate Caches/Restart -> Invalidate And Restart文件->使缓存无效/重新启动->无效并重新启动

Put your mouse over and press ⌥ Option + Enter , then click on Add library... (most of the cases the first option);将鼠标放在上面并按⌥ Option + Enter ,然后单击 Add library... (大多数情况下是第一个选项);

Otherwise:否则:

File ▸ Invalidate Caches/Restart ▸ Invalidate And Restart文件 ▸ 使缓存无效/重新启动 ▸ 无效并重新启动

then:然后:

First of all resolve all the dependency using首先使用解决所有依赖项

mvn dependency:resolve

and if still you see the error, cannot resolve @SpringBootApplication如果您仍然看到错误,则无法解决 @SpringBootApplication

then in pom.xml, add the version this version you can also get from https://start.spring.io/ which you would have selected while creating zip file for spring-boot project然后在 pom.xml 中,添加这个版本,您也可以从https://start.spring.io/获得该版本,您在为 spring-boot 项目创建 zip 文件时会选择该版本

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>2.5.3</version>
</plugin>

after this let the dependency to resolve by saving pom.xml and once it's resolved error will be gone在此之后,通过保存 pom.xml 来解决依赖关系,一旦解决,错误就会消失

Error sometimes happens when wrong class mentioned as per below错误有时会在以下提到的错误类中发生

Spring**Boot**Application.run(OrderServiceApplication.class);

It should be like below and as per other useful tips by others to clear the cache will also help to resolve your problem.它应该如下所示,并且根据其他人清除缓存的其他有用提示也将有助于解决您的问题。

SpringApplication.run(OrderServiceApplication.class);

May be you need to change the maven path from you IDE.可能您需要从 IDE 更改 Maven 路径。 In you intellij IDE, go to在你的 intellij IDE 中,转到

settings -> Build, Execution, Deployment -> Build tools -> Maven设置 -> 构建、执行、部署 -> 构建工具 -> Maven

and from there click on the Maven home path dropdown and select the Bundled (Maven 3)然后从那里单击Maven 主路径下拉菜单并选择Bundled (Maven 3)

在此处输入图像描述

i had the same problem , a simple :我有同样的问题,很简单:

File -> Invalidate Caches/Restart -> Invalidate And Restart文件 -> 使缓存无效/重新启动 -> 无效并重新启动

then maven -> Reload Project然后 maven -> 重新加载项目

solve it解决这个问题

follow below steps.请按照以下步骤操作。 for me, It worked.对我来说,它奏效了。

  1. invalidate cache and restart.使缓存无效并重新启动。

  2. when intellij reopend, you can see gradle build script is detected( or maven)当intellij重新打开时,您可以看到检测到gradle构建脚本(或maven)

    just click 'build gradle' like message.只需单击消息之类的“构建 gradle”。

    then intellij will run build script, and dependencies also gonna be resolved.然后 intellij 将运行构建脚本,并且依赖项也将被解决。

Go inside the settings -> Build, Execution, Deployment -> Build tools -> Maven Go 里面的设置 -> 构建,执行,部署 -> 构建工具 -> Maven

and choose the maven home path as "Bundled (Maven 3)"并选择 maven 主路径作为“捆绑(Maven 3)”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM