0

我有一个现有的 Spring Boot 项目 (1.4.3.RELEASE),并且正在尝试使用 Cloud AWS 项目添加一些功能。但是,在实例化我的 @Configuration 类之一时,仅将依赖项添加到 gradle 构建文件会导致明显的 cglib 问题。

将以下行添加到 gradle build 并运行应用程序:

编译(“org.springframework.cloud:spring-cloud-starter-aws-messaging:1.1.3.RELEASE”)

原因:

原因:org.springframework.beans.BeanInstantiationException:无法实例化 [com.***.application.config.AwsConfig$$EnhancerBySpringCGLIB$$5301ed81]:未找到默认构造函数;嵌套异常是 java.lang.NoSuchMethodException: com.***.application.config.AwsConfig$$EnhancerBySpringCGLIB$$5301ed81.()
    在 org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]

它抱怨在我的 @Configuration 类中找不到非空构造函数,但最新版本的 Spring 支持这些构造函数。如果我删除依赖项,应用程序可以正常启动。如何在不重新配置我的课程的情况下解决这个问题?等待 Cloud AWS 的更新版本?

4

1 回答 1

1

You need to configure your app to use BOM dependencies to avoid dependency conflicts. BOMs are more like a maven feature (you can read up here) but the Spring folks have come up with a Gradle plugin to allow the same behavior. Look into this Spring Blog Post for a full explanation. But basically adding this to your gradle config:

buildscript {
  repositories {
    mavenCentral()
  }
  dependencies {
    classpath "io.spring.gradle:dependency-management-plugin:1.0.0.RC1"
  }
}

apply plugin: "io.spring.dependency-management"

You can then do:

dependencyManagement {
  imports {
    mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.4.2.RELEASE'
  }
}

dependencies {
  compile "org.springframework.boot:spring-boot-starter-web"
}

On which you don't have to specify the actual dependency version for spring boot plugins.

于 2016-12-23T22:51:14.610 回答