SpringBoot DataSource配置

mri*_*974 5 spring jpa spring-boot

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

我把以下属性放在里面:

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.user=test
spring.datasource.password=test
spring.datasource.jdbcUrl=jdbc:postgresql://localhost:5432/test
Run Code Online (Sandbox Code Playgroud)

application.properties文件很好地被其他系统使用.但我不能让它为自动数据源配置工作.

我仍然得到这个例外:

org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database url for database type NONE.
Run Code Online (Sandbox Code Playgroud)

包含并加载postgresql驱动程序.我可以使用Configuration类和上面相同的参数配置数据源.

我还添加了@EnableAutoConfiguration@EnableJpaRepositoriesApplication.class.

有线索吗?

And*_*son 10

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

spring.datasource.jdbcUrl如果DataSource你正在使用的特定实现有一个setJdbcUrl方法(例如HikariCP),spring.datasource.url它将工作在任何支持的数据源.

使用spring.datasource.url还具有额外的好处,您无需指定,spring.datasource.driverClassName因为它将从URL推断.