I am encountering an error in my Spring Boot application when attempting to configure a DataSource. The error message reads as follows:
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.
This is my pom.xml:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>42.6.1</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-webmvc</artifactId>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.6.0.Beta1</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.6.0.Beta1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-dependencies</artifactId>
<version>4.1.0</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Context:
I have a Spring Boot application that successfully reads properties from a configuration server. Below are relevant snippets of my application's setup:
@Configuration
@SpringBootApplication
public class AdminApiApplication {
public static void main(String\[\] args) {
SpringApplication.run(AdminApiApplication.class, args);
}
}
bootstrap.yml (client Application):
spring:
cloud:
config:
uri: http://localhost:8888
enabled: true
name: spring-cloud-config-server
management:
endpoints:
web:
exposure:
include: "\*"
application.yml (Config Server):
server:
port: 8888
spring:
profiles:
active: git
security:
user:
name: \*\*\*\*
password: \*\*\*\*
logging:
level:
org.springframework.cloud.config: DEBUG
spring:
cloud:
config:
server:
git:
uri: https://github.com/*****/****.git
username: \*\*\*\*\*
password: \*\*\*\*\*\*
cloneOnStart: true
when i run config server, i'm getting the values from git:
spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=postgres
username: postgres
password: postgres
driverClassName: org.postgresql.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: update
dialect: org.hibernate.dialect.PostgreSQLDialect
server:
port: 8080
While the application can successfully read properties from the config server, upon starting the client application to retrieve properties from the server, the aforementioned error occurs.
While the application can successfully read properties from the config server, upon starting the client application to retrieve properties from the server, the aforementioned error occurs.
I would appreciate any insights into resolving this issue and properly configuring the DataSource in my Spring Boot application.
There is something wrong on your application.yml.
Use this one for your purpose :
spring:
datasource:
url: jdbc:postgresql://localhost:5432/postgres?currentSchema=postgres
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
jpa:
show-sql: true
hibernate:
ddl-auto: update
dialect: org.hibernate.dialect.PostgreSQLDialect
server:
port: 8080
your application cant find suitable driver attribute in your application.yml .