0
votes

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?

1
This version of AWS messaging is based on Spring Boot 1.3, which uses Spring 4.2 which doesn't support non-empty constructors. You could try forcing the spring dependency to 4.3 but the fact that it uses Spring Boot 1.3 probably makes it non working for 1.4 (internal API changes etc. for Boot).M. Deinum
Thanks for the response. I reconfigured the class to have an empty constructor and autowire the dependencies in but now even the autowiring behavior doesn't work correctly. Not sure why adding this would cause such a mess in core Spring behavior but oh well. I'll see if I can come up with a hack workaround.koreys
Also just to update... I downgraded the Spring Boot version to 1.3.8 and I still have the same problem where the configuration class does not get it's fields autowired. Remove that dependency and everything works as it should.koreys
Well of course you will still have the same issue as that was the whole issue to begin with. If anything you should force it to 1.4 but that will probably make other things not work .M. Deinum

1 Answers

1
votes

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.