|
|
@ -17,6 +17,7 @@
|
|
|
|
package org.springframework.boot.autoconfigure.data.mongo;
|
|
|
|
package org.springframework.boot.autoconfigure.data.mongo;
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.DB;
|
|
|
|
import com.mongodb.DB;
|
|
|
|
import com.mongodb.Mongo;
|
|
|
|
import com.mongodb.Mongo;
|
|
|
@ -24,7 +25,6 @@ import com.mongodb.MongoClient;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
|
|
import org.springframework.beans.factory.BeanFactory;
|
|
|
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
|
|
@ -103,24 +103,19 @@ public class MongoDataAutoConfiguration {
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnMissingBean(MongoConverter.class)
|
|
|
|
@ConditionalOnMissingBean(MongoConverter.class)
|
|
|
|
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
|
|
|
|
public MappingMongoConverter mappingMongoConverter(MongoDbFactory factory,
|
|
|
|
MongoMappingContext context, BeanFactory beanFactory) {
|
|
|
|
MongoMappingContext context, BeanFactory beanFactory,
|
|
|
|
|
|
|
|
CustomConversions conversions) {
|
|
|
|
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
|
|
|
|
DbRefResolver dbRefResolver = new DefaultDbRefResolver(factory);
|
|
|
|
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver,
|
|
|
|
MappingMongoConverter mappingConverter = new MappingMongoConverter(dbRefResolver,
|
|
|
|
context);
|
|
|
|
context);
|
|
|
|
try {
|
|
|
|
mappingConverter.setCustomConversions(conversions);
|
|
|
|
mappingConverter
|
|
|
|
|
|
|
|
.setCustomConversions(beanFactory.getBean(CustomConversions.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (NoSuchBeanDefinitionException ex) {
|
|
|
|
|
|
|
|
// Ignore
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return mappingConverter;
|
|
|
|
return mappingConverter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
public MongoMappingContext mongoMappingContext(BeanFactory beanFactory)
|
|
|
|
public MongoMappingContext mongoMappingContext(BeanFactory beanFactory,
|
|
|
|
throws ClassNotFoundException {
|
|
|
|
CustomConversions conversions) throws ClassNotFoundException {
|
|
|
|
MongoMappingContext context = new MongoMappingContext();
|
|
|
|
MongoMappingContext context = new MongoMappingContext();
|
|
|
|
context.setInitialEntitySet(new EntityScanner(this.applicationContext)
|
|
|
|
context.setInitialEntitySet(new EntityScanner(this.applicationContext)
|
|
|
|
.scan(Document.class, Persistent.class));
|
|
|
|
.scan(Document.class, Persistent.class));
|
|
|
@ -129,6 +124,7 @@ public class MongoDataAutoConfiguration {
|
|
|
|
context.setFieldNamingStrategy(
|
|
|
|
context.setFieldNamingStrategy(
|
|
|
|
(FieldNamingStrategy) BeanUtils.instantiate(strategyClass));
|
|
|
|
(FieldNamingStrategy) BeanUtils.instantiate(strategyClass));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
context.setSimpleTypeHolder(conversions.getSimpleTypeHolder());
|
|
|
|
return context;
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -141,6 +137,12 @@ public class MongoDataAutoConfiguration {
|
|
|
|
mongoTemplate.getConverter());
|
|
|
|
mongoTemplate.getConverter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
|
|
|
|
public CustomConversions customConversions() {
|
|
|
|
|
|
|
|
return new CustomConversions(Collections.emptyList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* {@link MongoDbFactory} decorator to respect
|
|
|
|
* {@link MongoDbFactory} decorator to respect
|
|
|
|
* {@link MongoProperties#getGridFsDatabase()} if set.
|
|
|
|
* {@link MongoProperties#getGridFsDatabase()} if set.
|
|
|
|