MongoDB 사용시, SpringBoot 자동설정을 이용할 경우 아래와 같이 _class 에 Entity Class 의 package 정보가 함께 저장됩니다.
이 부분을 제거하기 위해서는 DefaultMongoTypeMapper 설정을 변경하면 됩니다.
{
"_id" : NumberLong(112),
"name" : "마샤",
"tags" : [
"여자캐릭터",
"흑마법사"
],
"_class" : "com.company.model.entity.Actor"
}
자동설정 소스코드 org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration 참고
@Bean
@ConditionalOnMissingBean({MongoConverter.class})
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory, MongoMappingContext context, MongoCustomConversions conversions) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
mappingConverter.setCustomConversions(conversions);
return mappingConverter;
}
변경 후 ( 설정 추가: mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null)); )
@Configuration
public class MongoConfiguration {
@Bean
@ConditionalOnMissingBean(MongoConverter.class)
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
MongoMappingContext context, MongoCustomConversions conversions) {
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver, context);
mappingConverter.setCustomConversions(conversions);
mappingConverter.setTypeMapper(new DefaultMongoTypeMapper(null));
return mappingConverter;
}
}
'SpringBoot' 카테고리의 다른 글
Spring 6 의 HTTP Interface (0) | 2023.03.14 |
---|---|
Retrying Feign Calls (0) | 2023.03.14 |
RedisTemplate 과 Json Serializer 설정 (0) | 2019.07.09 |
restful json request response 패킷 로깅 필터 (1) | 2019.07.04 |
404 NoHandlerFoundException 설정 (1) | 2019.07.04 |