我在使用MongoDB配置创建GenericGroovyApplicationContext时遇到问题。 groovy配置如下:
package groovy
import com.mongodb.Mongo
import org.springframework.core.io.ClassPathResource
import org.springframework.data.mongodb.core.MongoTemplate
beans {
xmlns([ctx:'http://www.springframework.org/schema/context'])
xmlns([mongoNamespace:'http://www.springframework.org/schema/data/mongo'])
def config = new ConfigSlurper().parse(new ClassPathResource('groovy/mongodbconfig.groovy').URL)
mongo Mongo
mongoTemplate(MongoTemplate, mongo, config.mongo.dbname)
mongoNamespace.'repositories'('base-package':'mypackage.data.dao')
}
我收到以下错误(无论是否创建了mongoTemplate bean):
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'documentsRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ... 19 more Caused by: java.lang.IllegalArgumentException: [Assertion failed] - this argument is required; it must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.util.Assert.notNull(Assert.java:123) at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.(MongoRepositoryFactory.java:59) at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.getFactoryInstance(MongoRepositoryFactoryBean.java:95) at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.createRepositoryFactory(MongoRepositoryFactoryBean.java:79) at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:202) at org.springframework.data.mongodb.repository.support.MongoRepositoryFactoryBean.afterPropertiesSet(MongoRepositoryFactoryBean.java:108) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
调试后发现MongoRepositoryFactoryBean#setMongoOperations在使用xml spring配置时调用时未调用。 有没有人有想法如何解决它? 感谢。