从其他应用程序模块导入依赖项时,Spring Boot REST API将无法启动

时间:2019-09-12 14:36:20

标签: java spring maven spring-boot dependencies

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

我已经通过各种不同的来源尝试找出我的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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

此问题已通过添加导致问题的依赖项所需的spring依赖项得到解决!感谢您的回答