选择版本为 spring  boot 2.2.0版本

首先访问https://start.spring.io/

spring boot 入门安装 版本2.2.0

search for dependencies里面要选择WEB JPA DevTools,点击之后会生成一个springboot 工程。目录如下:

spring boot 入门安装 版本2.2.0

导入IDE,新建一个包(controller),创建一个测试类helloworld。代码如下:

@RestController
@RequestMapping(value="/hello")
public class HelloWorld {
    @RequestMapping(value="/world")
    public String hello(){
        return "hello world";
    }
}

启动Application类发现报下面错误:

To display the conditions report re-run your application with 'debug' enable


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-05-02 13:46:27.460 ERROR 5469 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
***************************
APPLICATION FAILED TO START
***************************

原因:

  spring boot默认会加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。

解决方法:

  在Application类上增加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) 或者 配置dataSource

 

如下:

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class DemoApplication {

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

}


启动后访问:

spring boot 入门安装 版本2.2.0

相关文章: