@SpringBootApplication cannot be resolved to a type In STS

会有一股神秘感。 提交于 2019-11-29 16:43:45

问题


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:


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.




回答5:


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




回答6:


import the following:

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



回答7:


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);
}



回答8:


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



来源:https://stackoverflow.com/questions/41668819/springbootapplication-cannot-be-resolved-to-a-type-in-sts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!