Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpringBoot DataSource configuration

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?

like image 203
mrik974 Avatar asked Nov 27 '14 16:11

mrik974


People also ask

How do you configure a DataSource in spring boot?

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.

What is the default DataSource in spring boot?

The primary datasource is autowired by default, and other datasources need to be autowired along with @Qualifier annotation.


1 Answers

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.

like image 78
Andy Wilkinson Avatar answered Sep 24 '22 19:09

Andy Wilkinson