@SpringBootApplication cannot be resolved to a typ

2020-02-10 03:06发布

问题:

I am very new to STS. I searched for this error in stackoverflow. I didn't find correct matching answer.

I am able to see the class in MavenDependencies seciton in STS but not able to add the annotation in my java class.

Your help will be appriciated. Thanks

回答1:

Go to your maven repository directory For windows on below path C:\Users\YourUser\.m2\repository\org\springframework\boot Then delete spring-boot-autoconfigure folder.

Now go to eclipse Right click on project -> Maven -> Update Project.

This solved the problem for me.



回答2:

Run bellow commands from command line

mvn clean dependency:tree
mvn clean compile

select project and do a maven->update This solved my problem



回答3:

Neither of the above solutions worked for me as my code was this

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.4.2.RELEASE</version>
</parent>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>    
<properties>
    <java.version>1.8</java.version>
</properties>

I was missing the <dependencies> tag which lead to this error.



回答4:

Add the import statement below your package declaration.

import org.springframework.boot.autoconfigure.SpringBootApplication;

You only need to add that annotation to your entry point, not every class. It goes on the same class that holds the main method to start Spring...

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


回答5:

Just change your spring boot version into 1.5.6 from 1.5.8. trust me i have tried every other solution but only this solution worked for me.



回答6:

Clear your org/springframework/boot folder under .m2/ file location and run mvn clean install command under project



回答7:

import the following:

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


回答8:

I had the same problem. You can resolve it with building the project with the "eclipse:eclipse" goal.