Java @SpringBootApplication 无法解析为 STS 中的类型
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41668819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
@SpringBootApplication cannot be resolved to a type In STS
提问by Abdul
I am very new to STS. I searched for this error in stackoverflow. I didn't find correct matching answer.
我对 STS 很陌生。我在 stackoverflow 中搜索了这个错误。我没有找到正确的匹配答案。
I am able to see the class in MavenDependencies seciton in STS but not able to add the annotation in my java class.
我能够在 STS 的 MavenDependencies 部分中看到该类,但无法在我的 Java 类中添加注释。
采纳答案by Foolish
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.
转到您的 Maven 存储库目录对于下面路径上的 Windows
C:\Users\YourUser\.m2\repository\org\springframework\boot
然后删除spring-boot-autoconfigure
文件夹。
Now go to eclipse Right click on project -> Maven -> Update Project
.
现在去 eclipse Right click on project -> Maven -> Update Project
。
This solved the problem for me.
这为我解决了这个问题。
回答by FMC
Add the import statement below your package declaration.
在包声明下方添加 import 语句。
import org.springframework.boot.autoconfigure.SpringBootApplication;
导入 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...
您只需要将该注释添加到您的入口点,而不是每个类。它位于包含启动 Spring 的主要方法的同一个类上......
public static void main(String[] args) {
SpringApplication.run(CourseAPIApp.class, args);
}
回答by Saravanan T
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.
只需将您的 Spring Boot 版本从 1.5.8 更改为 1.5.6。相信我,我已经尝试了所有其他解决方案,但只有这个解决方案对我有用。
回答by user2978065
I had the same problem. You can resolve it with building the project with the "eclipse:eclipse"
goal.
我有同样的问题。您可以通过构建具有"eclipse:eclipse"
目标的项目来解决它。
回答by Chaman
Run bellow commands from command line
从命令行运行波纹管命令
mvn clean dependency:tree
mvn clean compile
select project and do a maven->update This solved my problem
选择项目并执行 maven->update 这解决了我的问题
回答by Miraj Hamid
Clear your org/springframework/bootfolder under .m2/file location and run mvn clean installcommand under project
清除.m2/文件位置下的org/springframework/boot文件夹并在项目下运行mvn clean install命令
回答by Ashwani Sharma
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.
我错过了<dependencies>
导致此错误的标签。
回答by user12099683
import the following:
导入以下内容:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;