Skip to content

Commit

Permalink
MATE-145 : [FEAT] MongoDB 의존성 추가 및 설정 (#131)
Browse files Browse the repository at this point in the history
* MATE-145 : [FEAT] MongoDB 의존성 추가

* MATE-145 : [FEAT] MongoConfig 클래스 구현

- _class 필드가 저장되지 않도록 설정
  • Loading branch information
hongjeZZ authored Jan 9, 2025
1 parent f7fc9e2 commit cf05da5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/example/mate/common/config/MongoConfig.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit cf05da5

Please sign in to comment.