SpringBoot DataSource配置 [英] SpringBoot DataSource configuration
问题描述
我正在尝试使用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屋!