SpringBoot项目不加载数据源启动

1、未配置jdbc依赖项会报错找不到配置类(未配置yml、properties

org.springframework.beans.factory.UnsatisfiedDependencyException: 
Error creating bean with name 'dataSource': 
Unsatisfied dependency expressed through field 'basicProperties'; 
nested exception is org.springframework.beans.factory.BeanCreationException:
 Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': 
Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseType

2、已配置依赖项的通常情况会报url错误

Fail to configure a DataSource :'url' attribute is not specified ...

3、此时需要在yml 、properties中配置先排除jdbc配置Bean

spring.autoconfigure.exclude:org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

感兴趣的可以了解下类内部的配置详情

4、在启动类注解上排除Druid自动配置类

@SpringBootApplication(exclude={DruidDataSourceAutoConfigure.class})

5、maven进行clean后重新编译项目启动成功,接口正常访问(除数据库操作的接口)

PS:1、注意排除Bean不要出现引包错误;

        2、Spring版本2.0.3.RELEASE,不同版本排除类可能有差异,具体需要查看报错详情,思路事一样的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值