springboot initialization error on startup with mongodb on gorm/groovy

grails-orm, groovy, mongodb, spring, spring-boot

Solution

`gorm-mongodb-spring-boot` is incompatible with Spring Boot 1.2. It creates a bean named `mongoMappingContext` that prevents `MongoDataAutoConfiguration` from creating its own bean with the same name. You should see a message like this in the log:

2015-02-25 14:01:30.731  INFO 60231 --- [           main] a.ConfigurationClassBeanDefinitionReader : Skipping bean definition for [BeanMethod:name=mongoMappingContext,declaringClass=org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration]: a definition for bean 'mongoMappingContext' already exists. This top-level bean definition is considered as an override.

You can work around the problem by declaring your own `org.springframework.data.mongodb.core.mapping.MongoMappingContext` bean with a different name, for example:

@Bean
MongoMappingContext springDataMongoMappingContext() {
    return new MongoMappingContext()
}

Problem

Getting startup issues for this springboot project using MongoDB/GORM/Groovy on `Java 1.7.0_55`, gradle `1.11`, and `spring-boot-gradle-plugin:1.2.1.RELEASE`. I'm running the project as-is with the exception of the following change to `application.yml` for my remote mongodb: ``` spring: mongodb: host: "10.160.8.1" databaseName: "citydb" ``` **On startup, I'm seeing this bean initialization error with `mappingMongoConverter` ``` Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.data.mongodb.core.convert.MongoConverter]: : Error creating bean with name 'mappingMongoConverter' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.data.mongodb.core.mapping.MongoMappingContext]: : No qualifying bean of type [org.springframework.data.mongodb.core.mapping.MongoMapping Context] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.mongodb.core.mapping.MongoMappingCo ntext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [org /springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of typ e [org.springframework.data.mongodb.core.mapping.MongoMappingContext]: : No qualifying bean of type [org.springframework.data.mongodb.core.mapping.MongoMappin gContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested excepti on is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.mongodb.core.mapping.MongoMappingC ontext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} ``` I think this is the main issue: ``` Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingMongoConverter' defined in class path resou rce [org/springframework/boot/autoconfigure/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 1 of type [org.springframework.data.mongodb.core.mapping.MongoMappingContext]: : No qualifying bean of type [org.springframework.data.mongodb.core.mapping.Mon goMappingContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.mongodb.core.mapping.Mongo MappingContext] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java: 1111) ``` Could this be a GORM dependency issue? I'm using the latest, `org.grails:gorm-mongodb-spring-boot:1.1.0.RELEASE` Tracked as issue on github: https://github.com/spring-guides/gs-accessing-data-gorm-mongodb/issues/6

Original source