|
@@ -4,11 +4,14 @@ import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
|
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
import org.springframework.beans.factory.config.BeanDefinition;
|
|
|
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
|
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
|
|
|
|
|
|
|
|
|
+import org.apache.log4j.Logger;
|
|
|
|
|
+
|
|
|
import com.mongodb.MongoClient;
|
|
import com.mongodb.MongoClient;
|
|
|
|
|
|
|
|
import org.mongodb.morphia.Datastore;
|
|
import org.mongodb.morphia.Datastore;
|
|
@@ -18,20 +21,30 @@ import org.mongodb.morphia.annotations.Entity;
|
|
|
@Configuration
|
|
@Configuration
|
|
|
@SpringBootApplication
|
|
@SpringBootApplication
|
|
|
public class DBConfig {
|
|
public class DBConfig {
|
|
|
|
|
+ static Logger log = Logger.getLogger(DBConfig.class.getName());
|
|
|
|
|
+
|
|
|
|
|
+ @Value("${spring.data.mongodb.database:ieat}")
|
|
|
|
|
+ private String dbName;
|
|
|
|
|
+
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private MongoClient mongoClient;
|
|
private MongoClient mongoClient;
|
|
|
|
|
|
|
|
@Bean
|
|
@Bean
|
|
|
public Datastore datastore() {
|
|
public Datastore datastore() {
|
|
|
Morphia morphia = new Morphia();
|
|
Morphia morphia = new Morphia();
|
|
|
-
|
|
|
|
|
ClassPathScanningCandidateComponentProvider entityScanner =
|
|
ClassPathScanningCandidateComponentProvider entityScanner =
|
|
|
new ClassPathScanningCandidateComponentProvider(true);
|
|
new ClassPathScanningCandidateComponentProvider(true);
|
|
|
entityScanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
|
|
entityScanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));
|
|
|
- /*for (BeanDefinition candidate : scanner.findCandidateComponents("name.tflucke.ieat2")) {
|
|
|
|
|
- morphia.map(Class.forName(candidate.getBeanClassName()));
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ for (BeanDefinition candidate : entityScanner.findCandidateComponents("name.tflucke.ieat2.models")) {
|
|
|
|
|
+ morphia.map(Class.forName(candidate.getBeanClassName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (ClassNotFoundException cnfe) {
|
|
|
|
|
+ log.error("Class found, then not found: ");
|
|
|
|
|
+ log.error(cnfe);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return morphia.createDatastore(mongoClient, "dataStoreInstanceId");
|
|
|
|
|
|
|
+ return morphia.createDatastore(mongoClient, dbName);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|