SO i have a spring boot application, and configured postgresql, as below
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql:dburl
spring.datasource.username=admin
spring.datasource.password=XXX
But I get failure on application start up that a datasource is not created
No qualifying bean of type 'javax.sql.DataSource' available
I decided to create a datasource bean instead:
@Configuration
public class DataSourceConfig {
@Bean
public DataSource dataSource() {
// Create and configure the DataSource here
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hibernate.dialect.PostgreSQLDialect");
dataSource.setUrl("jdbc:postgresql://localhost:5432/your-database");
dataSource.setUsername("your-username");
dataSource.setPassword("your-password");
return dataSource;
}
}
This seems to create the datasource connection.
But i dont understand why i cannot create the datasource from the properties.
2
Answers
Can you please show us your dependencies? If using Maven as your build tool, please check to see if you have this (please add, if you don’t and try again):
In your given sample you are missing port number for Postgres.
It is very simple to connect to Postgres using spring boot. Try following –
pom.xml
application.properties