I wanted to connect my application from spring boot with postgresql running in docker I am doing everything according to this tutorial – https://www.youtube.com/watch?v=8fbfHu8isI4&t=1452s , but I keep getting the same error:
Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled. 2021-08-02 16:18:56.400 ERROR 4169 — [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Failed to configure a DataSource: ‘url’ attribute is not specified and no embedded datasource could be configured.
Reason: Failed to determine a suitable driver class
Action:
Consider the following: If you want an embedded database (H2, HSQL or Derby), please put it on the classpath. If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).
Process finished with exit code 1
This is connecting with database
PostgresDataSource:
package com.example.restservice.datasource; import com.zaxxer.hikari.HikariDataSource; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; public class PostgresDataSource { @Bean @ConfigurationProperties("app.datasource") public HikariDataSource hikariDataSource() { return DataSourceBuilder .create() .type(HikariDataSource.class) .build(); } }
in application.yml
app: datasource: jdbcUrl: jdbc:postgresql://localhost:5432/drmdb username: postgres password: password pool-size: 30
I have these problems in application.yml and I have no idea what is wrong
Advertisement
Answer
You have a typo in this line:
jdbcUrl: jdbc:postgresql://localhost:5432/drmdb
You should fix it to:
jdbc-url: jdbc:postgresql://localhost:5432/drmdb
When using the guides, always look at the description. Sometimes there is a source code.
As @grekier stated you should also add @Configuration
to PostgresDatasource
class.