16

I imported a Spring Initializr build to IntelliJ and then run it as a Spring Boot build. 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. I also followed these steps as well: Cannot resolve symbol 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);
    }
}
Kevin Summersill
  • 562
  • 2
  • 7
  • 21

4 Answers4

37

Try it:
File -> Invalidate Caches/Restart -> Invalidate And Restart

B_Osipiuk
  • 740
  • 6
  • 15
10

Put your mouse over and press ⌥ Option + Enter, then click on Add library... (most of the cases the first option);

Otherwise:

File ▸ Invalidate Caches/Restart ▸ Invalidate And Restart

then:

abrahamcalf
  • 6,176
  • 3
  • 39
  • 50
2

First of all resolve all the dependency using

mvn dependency:resolve

and if still you see the error, cannot resolve @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

<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

Vivek Singh
  • 530
  • 4
  • 9
0

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);
tripleee
  • 158,107
  • 27
  • 234
  • 292