[英]Spring Cloud AWS cglib issue
我有一個現有的Spring Boot項目(1.4.3.RELEASE),正在嘗試使用Cloud AWS項目添加一些功能。 但是,僅將依賴項添加到gradle構建文件中會在實例化我的@Configuration類之一時引起明顯的cglib問題。
將以下行添加到gradle構建並運行應用程序:
compile("org.springframework.cloud:spring-cloud-starter-aws-messaging:1.1.3.RELEASE")
原因:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.***.application.config.AwsConfig$$EnhancerBySpringCGLIB$$5301ed81]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.***.application.config.AwsConfig$$EnhancerBySpringCGLIB$$5301ed81.() at 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的更新版本?
您需要將您的應用程序配置為使用BOM依賴關系,以避免依賴關系沖突。 BOM更像是一個maven功能(您可以在此處閱讀),但是Spring人員已經提出了Gradle插件來允許相同的行為。 查看此Spring Blog Post以獲取完整說明。 但基本上將其添加到您的gradle配置中:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "io.spring.gradle:dependency-management-plugin:1.0.0.RC1"
}
}
apply plugin: "io.spring.dependency-management"
然后,您可以執行以下操作:
dependencyManagement {
imports {
mavenBom 'org.springframework.boot:spring-boot-starter-parent:1.4.2.RELEASE'
}
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-web"
}
您不必在其上為Spring Boot插件指定實際的依賴版本。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.