Fix backend database connectivity in compose.yml by renaming to spring.mongodb.uri, adding credentials, and introducing healthcheck

This commit is contained in:
nessar committed 2026-08-17 14:18:14 +02:00
1 parent e69cc1a49f
commit 53d0c886a6
7 files changed
+28 -6

No files matched your search

@@ -4,9 +4,15 @@ import fr.nessar.lmnporganizer.backend.model.Landlord;
import fr.nessar.lmnporganizer.backend.repository.LandlordRepository;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
@Component
@ConditionalOnProperty(
name = "lmnp.data-initializer.enabled",
havingValue = "true",
matchIfMissing = true
)
public class DataInitializer implements ApplicationRunner {
private final LandlordRepository landlordRepository;
@@ -1,3 +1,3 @@
spring.application.name=backend
spring.data.mongodb.uri=${MONGODB_URI:mongodb://localhost:27017/lmnp}
spring.mongodb.uri=${SPRING_DATA_MONGODB_URI:mongodb://localhost:27017/lmnp}
spring.security.oauth2.resourceserver.jwt.issuer-uri=${OIDC_ISSUER_URI:http://localhost:8090/realms/voidAuth}
@@ -6,7 +6,7 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@SpringBootTest
@SpringBootTest(properties = "lmnp.data-initializer.enabled=false")
class BackendApplicationTests {
@MockitoBean
@@ -14,7 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import org.springframework.security.oauth2.jwt.JwtDecoder;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
@SpringBootTest
@SpringBootTest(properties = "lmnp.data-initializer.enabled=false")
@AutoConfigureMockMvc
class HelloControllerTest {
@@ -22,7 +22,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@SpringBootTest(properties = "lmnp.data-initializer.enabled=false")
@AutoConfigureMockMvc
class ApartmentControllerTest {
+16 -2
View File
@@ -4,8 +4,17 @@ services:
container_name: lmnp-mongodb
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: adminpassword
volumes:
- mongodb_data:/data/db
healthcheck:
test: ["CMD", "mongosh", "--username", "admin", "--password", "adminpassword", "--eval", "db.adminCommand('ping')"]
interval: 5s
timeout: 5s
retries: 5
# - ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
backend:
build:
@@ -15,10 +24,11 @@ services:
ports:
- "8080:8080"
environment:
MONGODB_URI: mongodb://mongodb:27017/lmnp
SPRING_DATA_MONGODB_URI: mongodb://admin:adminpassword@mongodb:27017/lmnp?authSource=admin
OIDC_ISSUER_URI: ${OIDC_ISSUER_URI:-http://localhost:8090/realms/voidAuth}
depends_on:
- mongodb
mongodb:
condition: service_healthy
frontend:
build:
@@ -35,3 +45,7 @@ services:
volumes:
mongodb_data:
networks:
default:
name: lmnp-net
+2
View File
@@ -0,0 +1,2 @@
db = db.getSiblingDB('lmnp');
db.createCollection('_init');