java - 用于创建数据源的spring boot源代码

标签 java spring spring-boot jdbc

我正在尝试通过 spring-boot 源代码来获得对其内部工作的更多信心。

例如:
当您使用以下属性时:

spring.datasource.url=jdbc:h2:./data/test
spring.datasource.username=sa
spring.datasource.password=as

spring boot 将尝试通过解析 spring.datasource.url 属性来猜测您需要的 jdbc 驱动程序,并在类路径中查找所需的驱动程序。

我们可以通过阅读 Spring 文档来推断这种行为:

You often do not need to specify the driver-class-name, since Spring Boot can deduce it for most databases from the url.

For a pooling DataSource to be created, we need to be able to verify that a valid Driver class is available, so we check for that before doing anything. In other words, if you set spring.datasource.driver-class-name=com.mysql.jdbc.Driver, then that class has to be loadable.

我认为负责的代码可以在 here 附近的某处找到.

可是我好像找不到。

你能帮我解释一下吗?

最佳答案

JDBC 驱动程序类名由 DatabaseDriver enum 中的常量控制.查看此枚举如何用于了解解析数据源 URL 属性的位置,例如在 DataSourceConfiguration 中,您会发现:

DatabaseDriver databaseDriver = DatabaseDriver
                .fromJdbcUrl(properties.determineUrl());

关于java - 用于创建数据源的spring boot源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55476104/

相关文章:

java - Android 工作室抛出 IOException : Operation not permitted

java - 使用较新版本的 Android Studio 构建应用程序一年后广告停止运行

java - 单元测试 spring data mongodb 自定义转换器

java - 无法从命令提示符运行 Spring Boot 应用程序

java - 在 ReSTLet 中,ReSTLet 类和 Resource 类有什么区别?

java - Spring boot 1.5.6 中的 RxJava 2

java - Spring - 使用 x-www-form-urlencoded 编码 POST 请求错误

spring-mvc - 如何从 pom.xml 中查找重复的依赖项

spring-boot - 尝试 Autowiring ClientResources 时出现问题

java - 如何在java中获取非常长的输入