I have Spring Boot application that I try to connect to my local database. I can run the file as a regular Java file and it connects to the database with no error. However, when I run mvn clean spring-boot:run
it prints the following output.
***************************
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
In my pom.xml I have
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
I checked the Maven dependencies and postgresql-42.2.19.jar is in there.
In my application-default.yml I have as
spring:
datasource:
driverClassName: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/pharmacy
username: ****
password: ****
platform: postgresql
initialize: false
continue-on-error: false
This is suggested by https://www.baeldung.com/spring-boot-failed-to-configure-data-source
CodePudding user response:
You are having database properties in application-default.yml
which only will be activated when you use "default" spring profile.
So, either use "default" spring profile (not maven profile) or move the properties to application.yml
which will be used by default whether you use any profiles or not.