Ebram Sherif
Ebram Sherif

Reputation: 187

Spring boot parent starter dependency override

So the current version does not use spring-data-mongodb 2.1.0 which I need to use ..

The problem is every-time i simply override the dependency in the POM by adding

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>2.1.1.RELEASE</version>
</dependency>

I end up getting a compile error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.mongo.MongoHealthIndicatorConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mongoTemplate' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mongoTemplate' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingMongoConverter' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'mappingMongoConverter' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDataAutoConfiguration.class]: Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.data.mapping.context.AbstractMappingContext.setApplicationContext(Lorg/springframework/context/ApplicationContext;)V

Upvotes: 0

Views: 4921

Answers (4)

zhang
zhang

Reputation: 1

I also encountered this problem, it seems that in the low version of the spring boot can not be resolved, because MongoTransactionManager requires spring-data-mongodb version is greater than 2.1.0, and my org.springframework.data only 2.0.6.

Upvotes: 0

Beezer
Beezer

Reputation: 1108

As per @Boris answer, if you do the following you can prove that he is correct. Go here: https://start.spring.io/ Select the following: enter image description here

Create the project demo. If you then expand and import into Intellij, and then get the effective POM and search for the original requirement you will find this which is one revision above the original asked. What would be great is if there is a site that shows all the combinations of revisions for a version of Spring boot...if anyone knows please add to this. Thanks. enter image description here

Upvotes: 1

Boris
Boris

Reputation: 24453

Quote from Spring Boot in Action book, p.37:

...take caution when overriding the dependencies that are pulled in transitively by Spring Boot starter dependencies. Although different versions may work fine, there’s a great amount of comfort that can be taken knowing that the versions chosen by the starters have been tested to play well together. You should only override these transitive dependencies under special circumstances (such as a bug fix in a newer version).

I personally would not take such a risk of overriding the spring-data-mongodb version.

If you really need to use the latest version of spring-data-mongodb I recommend upgrading the version of Spring Boot to 2.1.0.

Upvotes: 4

markusw
markusw

Reputation: 2065

The API of AbstractMappingContext has changed in newer versions and therefore is not compatible with your current spring-boot version.

I suggest you upgrade the whole spring-boot version to that one version that fits your desired spring-data-mongo version.

EDIT:

I'm afraid there is not spring-boot support for the 2.1.1 version yet. The newest one is 2.0.6.RELEASE that uses org.springframework.data:spring-data-mongodb:2.0.11.RELEASE

Upvotes: 0

Related Questions