Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mongodb.core.MongoTemplate]: Factory method 'getMongoTemplate' threw exception; nested exception is java.lang.IllegalArgumentException: Database name must not be empty!
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:620) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- ... 55 common frames omitted
- Caused by: java.lang.IllegalArgumentException: Database name must not be empty!
- at org.springframework.util.Assert.hasText(Assert.java:284) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- at org.springframework.data.mongodb.core.MongoDbFactorySupport.<init>(MongoDbFactorySupport.java:71) ~[spring-data-mongodb-2.1.2.RELEASE.jar:2.1.2.RELEASE]
- at org.springframework.data.mongodb.core.SimpleMongoDbFactory.<init>(SimpleMongoDbFactory.java:69) ~[spring-data-mongodb-2.1.2.RELEASE.jar:2.1.2.RELEASE]
- at org.springframework.data.mongodb.core.SimpleMongoDbFactory.<init>(SimpleMongoDbFactory.java:59) ~[spring-data-mongodb-2.1.2.RELEASE.jar:2.1.2.RELEASE]
- at org.tutoring.web.mongo.config.AbstractMongoConfig.mongoDbFactory(AbstractMongoConfig.java:23) ~[classes/:na]
- at org.tutoring.web.mongo.config.PrimaryMongoConnection.getMongoTemplate(PrimaryMongoConnection.java:28) ~[classes/:na]
- at org.tutoring.web.mongo.config.PrimaryMongoConnection$$EnhancerBySpringCGLIB$$c9a41f43.CGLIB$getMongoTemplate$0(<generated>) ~[classes/:na]
- at org.tutoring.web.mongo.config.PrimaryMongoConnection$$EnhancerBySpringCGLIB$$c9a41f43$$FastClassBySpringCGLIB$$f5203966.invoke(<generated>) ~[classes/:na]
- at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363) ~[spring-context-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- at org.tutoring.web.mongo.config.PrimaryMongoConnection$$EnhancerBySpringCGLIB$$c9a41f43.getMongoTemplate(<generated>) ~[classes/:na]
- at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
- at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
- at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_191]
- at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_191]
- at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.2.RELEASE.jar:5.1.2.RELEASE]
- ... 56 common frames omitted
- @Data
- public abstract class AbstractMongoConfig {
- //Mongo DB Properties
- private String host, database;
- private int port;
- /*
- * Method that creates MongoDbFactory
- * Common to both of the MongoDb connections
- */
- public MongoDbFactory mongoDbFactory() {
- return new SimpleMongoDbFactory(getMongoClient(), database);
- }
- y dos clases, una para cada BD:
- @Configuration
- @EnableMongoRepositories(basePackages = {"org.tutoring.web.primary.repository"}, mongoTemplateRef = "primaryMongoTemplate")
- @ConfigurationProperties(prefix = "primary.mongodb")
- public class PrimaryMongoConnection extends AbstractMongoConfig {
- @Primary
- @Override
- @Bean(name = "primaryMongoTemplate")
- public MongoTemplate getMongoTemplate() {
- return new MongoTemplate(mongoDbFactory());
- }
- }
- private MongoClient getMongoClient() {
- return new MongoClient(host, port);
- }
- abstract public MongoTemplate getMongoTemplate();
- @Configuration
- @EnableMongoRepositories(
- basePackages = {"org.tutoring.web.secondary.repository"},
- mongoTemplateRef = "secondaryMongoTemplate")
- @ConfigurationProperties(prefix = "secondary.mongodb")
- public class SecondaryMongoConnection extends AbstractMongoConfig {
- @Override
- public
- @Bean(name = "secondaryMongoTemplate")
- MongoTemplate getMongoTemplate() {
- return new MongoTemplate(mongoDbFactory());
- }
- }
- primary.mongodb.host=127.0.0.1
- primary.mongodb.port=27017
- primary.mongodb.database=TutoringDb
- secondary.mongodb.host=127.0.0.1
- secondary.mongodb.port=27017
- secondary.mongodb.database=tokensDb
Add Comment
Please, Sign In to add comment