0

I downloaded jdk 11, and maven 3.6.3 and Itellj Idea and Import a project:

mvn clean install 

But I always get this error:

Cannot resolve symbol 'SpringBootApplication'

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.xxx.xxx.sofa</groupId>
        <artifactId>sofa-spring-boot-pom-parent</artifactId>
        <version>1.0.10</version>
    </parent>



    <properties>
        <java.version>11</java.version>
        <spring-boot.version>2.3.2.RELEASE</spring-boot.version>
        <postgres.version>42.2.14</postgres.version>
        <h2.version>1.4.200</h2.version>
        <swagger.version>2.9.2</swagger.version>
    </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-web</artifactId>
        </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>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger.version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger.version}</version>
        </dependency>

        <!-- DATABASE -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>

        <!-- OPTIONAL TOOLS -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>

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

</project>

I tried to delete the .idea folder or "invalid cache and restart" but nor the first neither the second approach fixed the problem. There is a similar question Cannot resolve symbol SpringApplication but the answer didn't resolve my issue. how can I fix that?

Slim
  • 5,527
  • 13
  • 45
  • 81
  • Right click on the pom.xml and select Maven -> Reload project – Simon Martinelli Aug 04 '20 at 08:48
  • You get the error during the build on command line? If so you have missed to add dependencies to your pom file... – khmarbaise Aug 04 '20 at 08:53
  • Is `@SpringBootApplication` available at compile time? do you have corresponding dependency in the compile scope? how you try to run your project? – Giorgi Tsiklauri Aug 04 '20 at 09:08
  • @khmarbaise No error during the build. Build succeed – Slim Aug 04 '20 at 09:08
  • @GiorgiTsiklauri I edited my question and I added the pom.xml – Slim Aug 04 '20 at 09:12
  • Are you sure you import the annotation? – Giorgi Tsiklauri Aug 04 '20 at 09:27
  • @GiorgiTsiklauri I'm sorry but I don't understand your question. the clean and install executed successfully. – Slim Aug 04 '20 at 09:52
  • Do you use Lombok plugin? Please try with it disabled. Also try File | Invalidate Caches/Restart.. | Invalidate and Restart. If problem remains please file [a support request](https://intellij-support.jetbrains.com/hc/en-us/requests/new) with idea.log (Help | Show Log in ... action) file attached after IDE restart opening the project and re-importing project in Maven tool window. – Andrey Aug 05 '20 at 17:20

5 Answers5

2

Running the following command solved for me this issue :

mvn idea:idea

Aditya Goel
  • 201
  • 1
  • 15
0

you seem to use Spring Boot version 1.0.1, @SpringBootApplication annotation was introduced in 1.2

J Asgarov
  • 2,526
  • 1
  • 8
  • 18
0

You are not using SpringBoot parent but your own, you need to add dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>${spring-boot.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>
Mladen Savić
  • 472
  • 4
  • 10
0

you need to add dependency

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

BRAIEK AYEMN
  • 89
  • 1
  • 6
0

I fixed this issue by downgrading the maven version.

Slim
  • 5,527
  • 13
  • 45
  • 81