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
The application.properties
file is well used by other systems. But I can't get it to work for the automatic datasource configuration.
I'm still getting this Exception :
org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database url for database type NONE.
The postgresql driver is included and loaded. And I can configure the datasource using a Configuration
class, and the same parameters as above.
I've also added the @EnableAutoConfiguration
and @EnableJpaRepositories
to my Application.class
.
Any clues?
To access the Relational Database by using JdbcTemplate in Spring Boot application, we need to add the Spring Boot Starter JDBC dependency in our build configuration file. Then, if you @Autowired the JdbcTemplate class, Spring Boot automatically connects the Database and sets the Datasource for the JdbcTemplate object.
The primary datasource is autowired by default, and other datasources need to be autowired along with @Qualifier annotation.
You should use spring.datasource.url
to configure the JDBC URL rather than spring.datasource.jdbcUrl
.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With