spring org.springframework.boot.autoconfigure 无法在 eclipse 中解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27821311/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 00:16:47  来源:igfitidea点击:

org.springframework.boot.autoconfigure cannot be resolved in eclipse

springspring-boot

提问by dalei19

I imported the spring-boot-1.1.10.RELEASE.jar into my j2ee project. But i can not found the class of autoconfigure. Here is code:

我将 spring-boot-1.1.10.RELEASE.jar 导入到我的 j2ee 项目中。但是我找不到自动配置的类。这是代码:

import org.springframework.boot.autoconfigure;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;
@ComponentScan
@EnableAutoConfiguration
public class Application {
    public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
     }
 }

The Compile error:

编译错误:

The import org.springframework.boot.autoconfigure cannot be resolved

导入 org.springframework.boot.autoconfigure 无法解析

回答by Uzzal Podder

I had the same problem and I tried above solutions. But I have found a different issue.

我遇到了同样的问题,我尝试了上述解决方案。但我发现了一个不同的问题。

In latest springframework, this org.springframework.boot.autoconfigure.jdbc.DataSourceBuilderhas been moved to org.springframework.boot.jdbc.DataSourceBuilder. so you have to edit in import

在最新的springframework 中,这 org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder已移至 org.springframework.boot.jdbc.DataSourceBuilder. 所以你必须在导入中进行编辑

And then you will notice that you have to use DataSourceBuilder.create(classLoader)instead of new DataSourceBuilder(classLoader)

然后你会注意到你必须使用DataSourceBuilder.create(classLoader)而不是new DataSourceBuilder(classLoader)

回答by Foolish

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

转到您的 Maven 存储库目录对于下面路径上的 Windows C:\Users\YourUser\.m2\repository\org\springframework\boot然后删除spring-boot-autoconfigure文件夹。

Now go to eclipse and do maven update.

现在去eclipse并做maven更新。

回答by koe

There is a copy/paste error - the code from the official documentation (https://spring.io/guides/gs/rest-service/) is:

有一个复制/粘贴错误——来自官方文档(https://spring.io/guides/gs/rest-service/)的代码是:

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan
@EnableAutoConfiguration
public class Application {

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

The code in the question is missing ".EnableAutoConfiguration" in the first line.

问题中的代码在第一行中缺少“.EnableAutoConfiguration”。

回答by horsedevours

In case anyone else has this issue, I was able to solve this by deleting the spring-boot-autoconfigure artifacts from my local Maven repository and updating my project in Eclipse (which re-downloads the artifacts).

如果其他人遇到此问题,我可以通过从本地 Maven 存储库中删除 spring-boot-autoconfigure 工件并在 Eclipse(重新下载工件)中更新我的项目来解决此问题。

回答by Kishor K

if you are using eclise then Right button on project -> Maven -> Update Project

如果您使用的是 eclise,则在项目上右键 -> Maven -> 更新项目

回答by Siddhant Tanpure

If you are using IntelliJ IDEA Right click on project -> Maven -> Reimport Also, try "Generate source and update folder" below the reimport if above method doesn't work. No need to delete any spring or maven folder or files.

如果您使用的是 IntelliJ IDEA 右键单击​​项目 -> Maven -> 重新导入此外,如果上述方法不起作用,请尝试重新导入下方的“生成源和更新文件夹”。无需删除任何 spring 或 maven 文件夹或文件。