コード例 #1
0
  @Autowired
  @SuppressWarnings("unchecked")
  public void setMongo(Mongo mongo) throws Exception {

    CustomConversions conversions =
        new CustomConversions(
            Arrays.asList(DateToDateTimeConverter.INSTANCE, DateTimeToDateConverter.INSTANCE));

    MongoMappingContext mappingContext = new MongoMappingContext();
    mappingContext.setInitialEntitySet(
        new HashSet<Class<?>>(
            Arrays.asList(
                PersonWith_idPropertyOfTypeObjectId.class,
                PersonWith_idPropertyOfTypeString.class,
                PersonWithIdPropertyOfTypeObjectId.class,
                PersonWithIdPropertyOfTypeString.class,
                PersonWithIdPropertyOfTypeInteger.class,
                PersonWithIdPropertyOfPrimitiveInt.class,
                PersonWithIdPropertyOfTypeLong.class,
                PersonWithIdPropertyOfPrimitiveLong.class)));
    mappingContext.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
    mappingContext.afterPropertiesSet();

    MappingMongoConverter mappingConverter = new MappingMongoConverter(factory, mappingContext);
    mappingConverter.setCustomConversions(conversions);
    mappingConverter.afterPropertiesSet();

    this.mappingTemplate = new MongoTemplate(factory, mappingConverter);
  }
コード例 #2
0
 @Bean
 @DependsOn("customConversions")
 @Autowired
 public MappingMongoConverter mongoConverter() throws Exception {
   MongoMappingContext mappingContext = new MongoMappingContext();
   DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
   MappingMongoConverter mongoConverter = new MappingMongoConverter(dbRefResolver, mappingContext);
   mongoConverter.setCustomConversions(customConversions());
   mongoConverter.afterPropertiesSet();
   return mongoConverter;
 }