File tree Expand file tree Collapse file tree 4 files changed +32
-1
lines changed
java/com/CSO2/contentservice/config Expand file tree Collapse file tree 4 files changed +32
-1
lines changed Original file line number Diff line number Diff line change 44# IntelliJ
55.idea /
66* .iml
7+ .env
Original file line number Diff line number Diff line change @@ -19,6 +19,6 @@ USER spring:spring
1919
2020COPY --from=builder /app/target/*.jar app.jar
2121
22- EXPOSE 8080
22+ EXPOSE 8086
2323
2424ENTRYPOINT ["java" , "-jar" , "app.jar" ]
Original file line number Diff line number Diff line change 11package com .CSO2 .contentservice .config ;
22
3+ import com .mongodb .ConnectionString ;
4+ import com .mongodb .MongoClientSettings ;
5+ import com .mongodb .client .MongoClient ;
6+ import com .mongodb .client .MongoClients ;
7+ import org .springframework .beans .factory .annotation .Value ;
8+ import org .springframework .context .annotation .Bean ;
39import org .springframework .context .annotation .Configuration ;
10+ import org .springframework .data .mongodb .core .MongoTemplate ;
411import org .springframework .data .mongodb .repository .config .EnableMongoRepositories ;
512
613@ Configuration
714@ EnableMongoRepositories (basePackages = "com.CSO2.contentservice.repository" )
815public class MongoConfig {
16+
17+ @ Value ("${spring.data.mongodb.uri:mongodb://localhost:27017/CSO2_content_service}" )
18+ private String mongoUri ;
19+
20+ @ Value ("${spring.data.mongodb.database:CSO2_content_service}" )
21+ private String database ;
22+
23+ @ Bean
24+ public MongoClient mongoClient () {
25+ System .out .println ("MongoDB Connection URI: " + mongoUri .replaceAll (":[^:@]+@" , ":****@" ));
26+
27+ MongoClientSettings settings = MongoClientSettings .builder ()
28+ .applyConnectionString (new ConnectionString (mongoUri ))
29+ .build ();
30+
31+ return MongoClients .create (settings );
32+ }
33+
34+ @ Bean
35+ public MongoTemplate mongoTemplate () {
36+ return new MongoTemplate (mongoClient (), database );
37+ }
938}
Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ server.port=${SERVER_PORT:8086}
33
44# MongoDB Configuration (override via env vars in production)
55spring.data.mongodb.uri =${MONGODB_URI:mongodb://localhost:27017/CSO2_content_service}
6+ spring.data.mongodb.database =${MONGODB_DATABASE:CSO2_content_service}
67
You can’t perform that action at this time.
0 commit comments