简体   繁体   中英

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

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 .

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

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: 在此处输入图片说明

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. 在此处输入图片说明

我也遇到了这个问题,看来在低版本的Spring Boot中无法解决,因为MongoTransactionManager要求spring-data-mongodb版本大于2.1.0,而我的org.springframework.data只有2.0.6。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM