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

dal*_*i19 8 spring spring-boot

我将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);
     }
 }
Run Code Online (Sandbox Code Playgroud)

编译错误:

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

Foo*_*ish 8

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

现在去eclipse并做maven更新.


Uzz*_*der 5

我有同样的问题,我试过上面的解决方案.但我发现了一个不同的问题.

在最新的springframework中,这 org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder 已经转移到了 org.springframework.boot.jdbc.DataSourceBuilder.所以你必须在导入时编辑

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


koe*_*koe 3

存在复制/粘贴错误 - 官方文档(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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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