SpringBoot DataSource配置 [英] SpringBoot DataSource configuration

查看:574
本文介绍了SpringBoot DataSource配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用application.properties文件配置Spring Boot必须使用的数据源.

I'm trying to use the application.properties file to configure the datasource Spring Boot will have to use.

我将以下属性放入其中:

I've put the following properties inside :

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.user=test
spring.datasource.password=test
spring.datasource.jdbcUrl=jdbc:postgresql://localhost:5432/test

application.properties文件已被其他系统很好地使用.但是我无法将其用于自动数据源配置.

The application.properties file is well used by other systems. But I can't get it to work for the automatic datasource configuration.

我仍然收到此异常:

org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database url for database type NONE.

已包含并加载了postgresql驱动程序.而且我可以使用Configuration类以及与上述相同的参数来配置数据源.

The postgresql driver is included and loaded. And I can configure the datasource using a Configuration class, and the same parameters as above.

我还在Application.class中添加了@EnableAutoConfiguration@EnableJpaRepositories.

有任何线索吗?

推荐答案

您应使用spring.datasource.url而不是spring.datasource.jdbcUrl来配置JDBC URL.

You should use spring.datasource.url to configure the JDBC URL rather than spring.datasource.jdbcUrl.

spring.datasource.jdbcUrl将起作用,其中spring.datasource.url将与任何受支持的数据源一起使用.

spring.datasource.jdbcUrl will work if the specific DataSource implementation that you're using has a setJdbcUrl method (HikariCP, for example) where as spring.datasource.url will work with any of the supported datasources.

使用spring.datasource.url的另一个好处是您无需指定spring.datasource.driverClassName,因为它将从URL推断出来.

Using spring.datasource.url also has the added benefit that you don't need to specify spring.datasource.driverClassName as it will be inferred from the url.

这篇关于SpringBoot DataSource配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆