java - 从不同的应用程序模块导入依赖项时,Spring Boot REST API 将不会启动

标签 java spring maven spring-boot dependencies

我正在使用 Spring Boot 构建 REST API,因为我们的其他 API 使用 Drop-wizard 并且不使用 Spring。我需要使用一些代码,特别是 JMS 代码来将消息发送到应用程序的各个不同部分,因此需要构建一个新的 API,以便我们可以从不同的模块导入依赖项。我的 API 工作得很好,直到我导入一个依赖项来访问已编写的 JMS 代码。

我已经通过各种不同的来源来尝试查找我的 Spring Boot 依赖项和其他模块使用的 Spring 依赖项之间是否存在任何不匹配的版本。

我咨询了我的同事(他们有 30 年的经验),但无法给出答案。

我尝试使用不同版本的 spring-boot 来查看是否可以解决问题。

我正在使用以下 Spring-Boot 父版本

 <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath />
</parent>

然后使用以下依赖项:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

我可以向不同的端点发送各种不同的 GET 和 POST 请求,并且一切正常,直到我将此依赖项放入我的 pom.xml 中(来自生产系统的另一个模块):

<dependency>
    <groupId>com.kinesisfleet.messaging</groupId>
    <artifactId>kinesis-messaging</artifactId>
</dependency>

系统的这个特定模块的 pom 使用 spring,并使用以下依赖项:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-core</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-beans</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-context</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-orm</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-tx</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework.data</groupId>
  <artifactId>spring-data-jpa</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-test</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-jms</artifactId>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
</dependency>

我们使用的Spring版本如下:

```Spring Version - 4.2.0.RELEASE
Spring Data Version - 1.8.2.RELEASE
Spring Integration Version - 4.1.6.RELEASE```

添加依赖项后,我无法启动应用程序并收到以下错误:

    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:201) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:673) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:519) ~[spring-context-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
    at com.kinesis.spring.api.KinesisCoreSpringApi.main(KinesisCoreSpringApi.java:21) [classes/:na]
Caused by: java.lang.NullPointerException: null
    at org.springframework.core.BridgeMethodResolver.findBridgedMethod(BridgeMethodResolver.java:60) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
    at org.springframework.beans.GenericTypeAwarePropertyDescriptor.<init>(GenericTypeAwarePropertyDescriptor.java:70) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.CachedIntrospectionResults.buildGenericTypeAwarePropertyDescriptor(CachedIntrospectionResults.java:348) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.CachedIntrospectionResults.<init>(CachedIntrospectionResults.java:302) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.CachedIntrospectionResults.forClass(CachedIntrospectionResults.java:189) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getCachedIntrospectionResults(BeanWrapperImpl.java:175) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getLocalPropertyHandler(BeanWrapperImpl.java:212) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.BeanWrapperImpl.getLocalPropertyHandler(BeanWrapperImpl.java:63) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyHandler(AbstractNestablePropertyAccessor.java:725) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.AbstractNestablePropertyAccessor.isWritableProperty(AbstractNestablePropertyAccessor.java:557) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1483) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1226) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-4.2.0.RELEASE.jar:4.2.0.RELEASE



    It looks to be some sort of version mismatch, between the imported 
    dependency and the spring boot parent version.

    I am finding this very frustrating ad have spent nearly two days 
    trying to figure this out. Although im a junior dev, i've fixed 
    these sorts of issues lots of times, but this one if proving 
    difficult.

    If anyone has any ideas or pointers It would be appreciated

   Thanks

最佳答案

您可以尝试使用此命令在maven中打印依赖关系树 mvn 依赖:树 查看添加依赖项时导致问题的版本

关于java - 从不同的应用程序模块导入依赖项时,Spring Boot REST API 将不会启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57909074/

相关文章:

java - 最快的 Java 自由可再发行数据库

java - Spring AOP切面不拦截带注释的方法

java - 访问多个 JpaRepositories 之前和之后运行函数

java - AnnotationConfigApplicationContext 中的 Quartz 调度程序

java - Wsimport 在 Java 11 中失败

java - Eclipse 中的 Thrift 错误

java - 供应商提供的 SSL 证书中 CN 的值应该是多少?

java - 无法使用 Jsoup 获取重复标签

java - 在类上调用静态方法?

maven - 从 MS bat 文件执行多个 maven 项目?