使用IDEA时,运行结果出现Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured

经过在网上查询得知因为导入了MyBatis的jar包,spring boot 会默认加载org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration这个类,而DataSourceAutoConfiguration类使用了@Configuration注解向spring注入了dataSource bean,又因为项目(eureka-server模块和短信模块)中并没有关于dataSource相关的配置信息,所以spring创建dataSource bean时因缺少相关的信息就会报错。
解决办法:在@SpringBootApplication注解上加上exclude,解除自动加载DataSourceAutoConfiguration。

浙公网安备 33010602011771号