From cf05da5c6c9798339936db9d3eada89a9003cbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=95=88=ED=99=8D=EC=A0=9C?= Date: Thu, 9 Jan 2025 15:01:51 +0900 Subject: [PATCH] =?UTF-8?q?MATE-145=20:=20[FEAT]=20MongoDB=20=EC=9D=98?= =?UTF-8?q?=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20(#131)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * MATE-145 : [FEAT] MongoDB 의존성 추가 * MATE-145 : [FEAT] MongoConfig 클래스 구현 - _class 필드가 저장되지 않도록 설정 --- build.gradle | 3 +++ .../mate/common/config/MongoConfig.java | 24 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 src/main/java/com/example/mate/common/config/MongoConfig.java diff --git a/build.gradle b/build.gradle index 269c37f4..ca72d6fb 100644 --- a/build.gradle +++ b/build.gradle @@ -40,6 +40,9 @@ dependencies { runtimeOnly 'com.h2database:h2' runtimeOnly 'com.mysql:mysql-connector-j' + // MongoDB + implementation 'org.springframework.boot:spring-boot-starter-data-mongodb' + // Logging implementation 'org.slf4j:slf4j-api' implementation 'ch.qos.logback:logback-classic' diff --git a/src/main/java/com/example/mate/common/config/MongoConfig.java b/src/main/java/com/example/mate/common/config/MongoConfig.java new file mode 100644 index 00000000..4f40807d --- /dev/null +++ b/src/main/java/com/example/mate/common/config/MongoConfig.java @@ -0,0 +1,24 @@ +package com.example.mate.common.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.MongoDatabaseFactory; +import org.springframework.data.mongodb.core.convert.DbRefResolver; +import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; +import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper; +import org.springframework.data.mongodb.core.convert.MappingMongoConverter; +import org.springframework.data.mongodb.core.mapping.MongoMappingContext; + +@Configuration +public class MongoConfig { + + @Bean + public MappingMongoConverter mappingMongoConverter(MongoDatabaseFactory mongoDatabaseFactory, + MongoMappingContext mongoMappingContext) { + DbRefResolver dbRefResolver = new DefaultDbRefResolver(mongoDatabaseFactory); + MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, mongoMappingContext); + converter.setTypeMapper(new DefaultMongoTypeMapper(null)); + + return converter; + } +}