Error creating bean with name ‘dataSource‘: Unsatisfied dependency expressed through field

问题如下
Caused by: 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/dao/DataAccessException
1
原因
spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration类,
DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean。因为工程中没有关于dataSource相关的配置信息,当spring创建dataSource bean因缺少相关的信息就会报错。

解决办法
在启动类上添加注解:exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class}
1
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
public class ThirdApplication {

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

}
————————————————

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

原文链接:https://blog.csdn.net/xenos2020/article/details/128850826

posted @ 2024-07-25 08:31  枫树湾河桥  阅读(104)  评论(0编辑  收藏  举报
Live2D