I have a simple Spring boot project that can connect to a PostgreSQL Database.
When I install the dependencies with mvn clean install, I get:
org.postgresql.util.PSQLException: The connection attempt failed during Maven install
A "solution" I found was using -DskipTests, but that doesn't solve the issue, it only postpones it.
Because when I do mvn test, I will get the same error.
How can we have a database connection that will not crash tests?
The dependencies are this:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
...
</dependencies>
PS:
The test is the automatically generated one, I think loading the context is what gives the error.
package com.hamza.ince.bonptitcoinapi;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class BonPtitCoinApiApplicationTests {
@Test
void contextLoads() {
}
}
- application.properties:
spring.datasource.url=jdbc:postgresql://postgresql-api:5432/annonce_db?user=annonce_username&password=annonce_password
spring.datasource.username= postgres
spring.datasource.password= password
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.dialect= org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driver-class-name=org.postgresql.Driver