项目场景:
项目场景:启动项目时报错Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
问题描述
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
原因分析:
直接翻译
如果您想要一个嵌入式数据库(H2、HSQL或Derby),请将其放在类路径上。
如果要从特定配置文件加载数据库设置,则可能需要激活它(当前没有激活的配置文件)。
导致这个问题的原因是因为在pom.xml 文件中,配置了数据连接技术 spring-boot-starter-jdbc 包 ,这个包可以让SpringBoot 为我们自动配置相应的数据访问设施,在启动时 ,SpringBoot 的自动装配机制就会去配置文件中找相关的数据库连接配置信息,找不到的时候就会抛出异常。
解决方案:
-
在配置文件中加入数据库配置信息
-
在启动类上加@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
DataSourceAutoConfiguration.class会自动查找配置文件里的数据库相关属性自动配置数据源,所以直接手动排除掉就可以啦!
我是本篇小编LXL
遇到Bug需要帮助,
欢迎加wx:
xmzl1988
备注"csdn博客“
温馨提示此为有偿服务;