java - Spring boot 忽略 application.yml 中的数据源 url

标签 java spring spring-boot

我发现 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/

相关文章:

jnlp 中的 Java Web Start 和数据库详细信息

java - 文件字符串制作目录而不是文件名

java - 如何阻止 jackson 在 Spring MVC 中将日期写为时间戳

java - 如何设置属性排序,当我使用Jpa时Example.of

java - 从 com.google.android.gms.vision.CameraSource 访问相机并增加/减少预览亮度

java - 使用 JPA 的 Spring Boot OnetoMany

java - Spring OAuth2 配置流程。我是否需要自己的登录 Controller 来登录用户以提供资源服务访问?

java - Spring 启动: Property file with place holder

java - 如何在 Spring Boot 9 :30 am to 4:00 pm every 5 mins? 之间运行作业

java - 如何在 Angular 应用程序上显示来自 springboot 的异常消息