繁体   English   中英

Spring Boot父启动器依赖项覆盖

[英]Spring boot parent starter dependency override

所以当前版本不使用spring.data-mongodb 2.1.0,我需要使用..

问题是每次我只要通过添加来简单地覆盖POM中的依赖项

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

我最终得到一个编译错误:

org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / actuate / autoconfigure / endpoint / web / ServletEndpointManagementContextConfiguration $ WebMvcServletEndpointManagementContextConfiguration.class]中创建名称为“ servletEndpointRegistrar”的bean时出错:通过工厂方法实例化Bean失败; 嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.act.ateu.endpoint.web.ServletEndpointRegistrar]:工厂方法servletEndpointRegistrar抛出了异常; 嵌套的异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / actuate / autoconfigure / health / HealthEndpointConfiguration.class]中创建名称为'healthEndpoint'的bean时出错:通过工厂方法实例化Bean失败; 嵌套的异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.health.HealthEndpoint]:工厂方法'healthEndpoint'引发了异常; 嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“ org.springframework.boot.actuate.autoconfigure.mongo.MongoHealthIndicatorConfiguration”的bean时出错:通过构造函数参数0表示的不满足的依赖关系; 嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]中创建名称为'mongoTemplate'的bean时出错:通过方法'表示的不满意依赖关系mongoTemplate'参数1; 嵌套的异常是org.springframework.beans.factory.UnsatisfiedDependencyException:创建在类路径资源[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]中定义的名称为'mappingMongoConverter'的bean时出错:通过方法'表达的不满意依赖关系mappingMongoConverter'参数1; 嵌套的异常是org.springframework.beans.factory.BeanCreationException:在类路径资源[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]中创建名称为'mongoMappingContext'的bean时出错。 嵌套异常是java.lang.NoSuchMethodError:org.springframework.data.mapping.context.AbstractMappingContext.setApplicationContext(Lorg / springframework / context / ApplicationContext;)V

引用《 Spring Boot in Action 》第37页的内容:

...在覆盖由Spring Boot启动程序依赖项传递而来的依赖项时要当心。 尽管不同的版本可能会很好地工作,但要知道入门者选择的版本已经过测试,可以很好地搭配使用,因此可以带来很多舒适感。 仅在特殊情况下(例如,较新版本中的错误修复),才应覆盖这些可传递依赖项。

我个人不会冒这样的风险来覆盖spring-data-mongodb版本。

如果您确实需要使用最新版本的spring-data-mongodb我建议将Spring Boot的版本升级到2.1.0

在较新的版本中, AbstractMappingContext的API已更改,因此与您当前的spring-boot版本不兼容。

我建议您将整个spring-boot版本升级到适合您所需的spring-data-mongo版本的版本。

编辑:

恐怕还没有对2.1.1版本的spring-boot支持。 最新的是使用org.springframework.data:spring-data-mongodb:2.0.11.RELEASE 2.0.6.RELEASE

按照@Boris的答案,如果您执行以下操作,则可以证明他是正确的。 转到此处: https : //start.spring.io/选择以下内容: 在此处输入图片说明

创建项目演示。 如果您随后扩展并导入Intellij,然后获得有效的POM并搜索原始要求,则将发现它比原始要求高出一个修订版本。 最好的是,如果有一个网站可以显示所有版本的Spring Boot的修订组合...如果有人知道,请添加此内容。 谢谢。 在此处输入图片说明

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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