简体   繁体   中英

Spring Cloud AWS cglib issue

I have an existing Spring Boot project (1.4.3.RELEASE) and am trying to add some features using the Cloud AWS project. However, merely adding the dependency to the gradle build file causes an apparent cglib problem when instantiating one of my @Configuration classes.

Adding the following line to gradle build and running the app:

compile("org.springframework.cloud:spring-cloud-starter-aws-messaging:1.1.3.RELEASE")

Causes:

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]

It's complaining about not finding a non-empty constructor in my @Configuration class, but those are supported in latest version of Spring. The app boots up fine if I remove the dependency. How to fix this without reconfiguring my classes? Wait for an updated version of Cloud AWS?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM