問題如下
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