From d7bae4bf720be3f8fab49f4d04425630c15da9bd Mon Sep 17 00:00:00 2001 From: Vincenzo Ingenito Date: Mon, 2 Oct 2023 21:14:26 +0200 Subject: [PATCH] feat: Update mongo config --- .../config/mongo/MongoDatabaseCFG.java | 10 +++++++++- .../config/mongo/MongoPropertiesCFG.java | 15 +++++---------- src/main/resources/application-dev.properties | 2 +- src/main/resources/application.properties | 1 + src/test/resources/application-test.properties | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoDatabaseCFG.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoDatabaseCFG.java index 5aa36c2..8c8c746 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoDatabaseCFG.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoDatabaseCFG.java @@ -25,6 +25,10 @@ import org.springframework.data.mongodb.core.convert.MappingMongoConverter; import org.springframework.data.mongodb.core.mapping.MongoMappingContext; +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClients; + import net.javacrumbs.shedlock.core.LockProvider; import net.javacrumbs.shedlock.provider.mongo.MongoLockProvider; @@ -45,7 +49,11 @@ public class MongoDatabaseCFG { */ @Bean public MongoDatabaseFactory createFactory(MongoPropertiesCFG props) { - return new SimpleMongoClientDatabaseFactory(props.getUri()); + ConnectionString connectionString = new ConnectionString(props.getUri()); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + return new SimpleMongoClientDatabaseFactory(MongoClients.create(mongoClientSettings), props.getSchemaName()); } /** diff --git a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoPropertiesCFG.java b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoPropertiesCFG.java index 8807510..7f7fc54 100644 --- a/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoPropertiesCFG.java +++ b/src/main/java/it/finanze/sanita/fse2/ms/gtw/rulesmanager/config/mongo/MongoPropertiesCFG.java @@ -11,28 +11,23 @@ */ package it.finanze.sanita.fse2.ms.gtw.rulesmanager.config.mongo; -import lombok.Data; -import lombok.EqualsAndHashCode; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; -import java.io.Serializable; +import lombok.Data; /** - * * Mongo properties configuration. */ @Data @Component -@EqualsAndHashCode(callSuper = false) -public class MongoPropertiesCFG implements Serializable { +public class MongoPropertiesCFG { - /** - * Serial version uid - */ - private static final long serialVersionUID = -7936473659737067416L; @Value("${data.mongodb.uri}") private String uri; + + @Value("${data.mongodb.schema-name}") + private String schemaName; } diff --git a/src/main/resources/application-dev.properties b/src/main/resources/application-dev.properties index 8d25c2e..ee3d904 100644 --- a/src/main/resources/application-dev.properties +++ b/src/main/resources/application-dev.properties @@ -5,7 +5,7 @@ management.server.port=8011 ### MONGODB ### data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse - +data.mongodb.schema-name=FSE_GTW ### EDS CLIENT (REST) ### eds.rest.secured=false diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ea70e61..559aafe 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -47,6 +47,7 @@ kafka.enablessl=true ### MONGODB ### data.mongodb.uri=mongodb://${MONGO_USER}:${MONGO_PASSWORD}@:/ +data.mongodb.schema-name=${MONGO_DBNAME} ### EDS CLIENT (REST) ### eds.rest.kspwd= diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties index 4463a15..b044a76 100644 --- a/src/test/resources/application-test.properties +++ b/src/test/resources/application-test.properties @@ -1,6 +1,6 @@ ### MONGODB ### data.mongodb.uri=mongodb://mongoadmin:secret@localhost:27888/fse - +data.mongodb.schema-name=FSE_GTW ### REDIS ### redis.hostname=localhost redis.port=6379