我发现 spring boot 会默默地忽略通过 org.springframework.boot.autoconfigure.jdbc.DataSourceProperties
加载的所有数据源属性。
我的 application.yml
包含:
spring:
datasource:
name: this is not ignored
url: this is ignored
在启动过程中我看到一行:
o.s.j.d.e.EmbeddedDatabaseFactory : Creating embedded database 'this is not ignored'
调试显示 DataSourceProperties
对象在调用 getUrl
期间没有设置任何属性(调试还显示异常被抛出,但它被默默地忽略,因为它在日志)。
Url 显然无效,但数据库已初始化。
在 1.2.7 版本上测试。
什么会导致这种奇怪的行为?如何进一步调试?
最佳答案
添加
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
</dependency>
依赖关系解决了问题。
问题是由 Spring Boot 自动配置魔法引起的 - 我没有使用正确的 Spring Boot 启动器。
关于java - Spring boot 忽略 application.yml 中的数据源 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33188808/