首页 文章

Spring启动父启动器依赖性覆盖

提问于
浏览
0

所以当前版本不使用我需要使用的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:在类路径资源中定义名称为'servletEndpointRegistrar'的bean时出错[org / springframework / boot / actuate / autoconfigure / endpoint / web / ServletEndpointManagementContextConfiguration $ WebMvcServletEndpointManagementContextConfiguration.class]:通过工厂进行Bean实例化方法失败;嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]:工厂方法'servletEndpointRegistrar'抛出异常;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名称为'healthEndpoint'的bean时出错[org / springframework / boot / actuate / autoconfigure / health / HealthEndpointConfiguration.class]:通过工厂方法进行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:在类路径资源中定义名为'mongoTemplate'的bean时出错[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]:通过方法表达的不满意的依赖关系' mongoTemplate'参数1;嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在类路径资源中定义名为'mappingMongoConverter'的bean时出错[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]:通过方法表达的不满意的依赖关系' mappingMongoConverter'参数1;嵌套异常是org.springframework.beans.factory.BeanCreationException:在类路径资源中定义名为'mongoMappingContext'的bean时出错[org / springframework / boot / autoconfigure / data / mongo / MongoDataAutoConfiguration.class]:bean的初始化失败;嵌套异常是java.lang.NoSuchMethodError:org.springframework.data.mapping.context.AbstractMappingContext.setApplicationContext(Lorg / springframework / context / ApplicationContext;)V

3 回答

  • 0

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

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

    编辑:

    我担心2.1.1版本还没有spring-boot支持 . 最新的2.0.6.RELEASE使用 org.springframework.data:spring-data-mongodb:2.0.11.RELEASE

  • 0

    引自Spring Boot in Action书,第37页:

    ...在重写Spring Boot starter依赖项传递的依赖项时要小心 . 虽然不同的版本可以正常工作,但是知道开始者选择的版本经过测试可以很好地协同工作,可以获得很大的舒适度 . 您应该只在特殊情况下覆盖这些传递依赖项(例如较新版本中的错误修复) .

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

    如果你真的需要使用最新版本的 spring-data-mongodb ,我建议将Spring Boot的版本升级到2.1.0 .

  • 2

    根据@Boris的回答,如果您执行以下操作,您可以证明他是正确的 . 到这里:https://start.spring.io/选择以下内容:
    enter image description here

    创建项目演示 . 如果你然后扩展并导入Intellij,然后获得有效的POM并搜索原始要求,你会发现这是一个高于原始要求的修订 . 如果有一个站点显示Spring启动版本的所有修订组合,那将是多么伟大...如果有人知道请添加到此 . 谢谢 .
    enter image description here

相关问题