spriing boot 启动报错:Cannot determine embedded database driver class for database type NONE

主代码:

package com.example.springboot.demo_001;


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

@SpringBootApplication
public class Demo001Application {

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

    }

}



控制层代码:
package com.example.springboot.demo_001;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class TestController {

    @ResponseBody
    @RequestMapping("/hello")
    public String hello( )
    {
        return "hello word";
    }

}

运行的时候发现了这个错误,上网查了查

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-04-26 11:26:01.811 ERROR 13832 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Cannot determine embedded database driver class for database type NONE

Action:

If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (no profiles are currently active).


Process finished with exit code 1
 

 

 

解决方案:

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

 

因为我仅仅只是使用spring boot来写一些很简单的例子来学习它,在Application类上增加@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

阻止spring boot自动注入dataSource bean

 

加入@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})语句

 

package com.example.springboot.demo_001;


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

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

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

    }

}

 

参考于:https://blog.csdn.net/hry2015/article/details/78513412

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值