I tried using ```@ConstructorBinding @Configurati...
# spring
e
I tried using
Copy code
@ConstructorBinding
@ConfigurationProperties("push")
data class PushServicesProperties(val snsClient: SnsClient) {

    data class SnsClient(
        val maxConnections: Int,
        val connectionTimeout: Int,
        val socketTimeout: Int,
        val proxyHost: String,
        val proxyPort: Int
    )
}
But I'm still getting
No default constructor found
for the
PushServiceProperties
class. Has anyone else had that problem? Everything looks normal...
e
Did you added this in build.gradle.kts?
Copy code
plugins {
  ...
  kotlin("kapt") version "1.3.60"
}

dependencies {
  ...
  kapt("org.springframework.boot:spring-boot-configuration-processor")
}
e
Yes - altho in maven.
oh ... waaaaaiiiiit.....
Kotlin 1.3.60 - but not kapt.... Gimme a sec 🙂
Do I need
kapt
to make
@ConstructorBinding
work? Or just to make metadata-generation work?
Well ... I've added it now, but it hasn't made a difference. Tho - for maven I'm not exactly sure what's required.
e
@EricJTurley I thought it was just for metadata generation
c
Encountered the same problem today after updating from 2.2.0.RC1 to 2.2.1.RELEASE. Found a workaround: Now we need to annotate embedded property classes with `@ConstructorBinding`as well. In your case:
Copy code
@ConstructorBinding
data class SnsClient(
//...
no other changes are necessary,
kapt
stuff is only needed for metadata generation.
k
is it workaround? it does make sense, doesn't it?
e
@Czar I had tried that, too, based on comments I saw in some Spring issues (or something). Didn't work for me. 😞
@kqr It's definitely a workaround. The
@ConstructorBinding
annotation should extend to the nested properties classes.
âž• 1
c
@EricJTurley strange...
e
Yeah. Just tried again. Specifically, I have a test:
Copy code
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE/*mocked*/,
                classes = EndpointRegistrationServicesConfiguration.class)
class PushServicePropertiesTest {

    @Autowired
    PushServicesProperties pushServicesProperties; // <--- Java properties class

    @Autowired
    PushProperties1 pushProperties1; // <--- Kotlin data properties class
}
And I get:
Copy code
ConfigurationPropertiesBindException
Could not bind properties to 'PushProperties1'
BeanInstantiationException 'PushProperties1'
No default constructor found
NoSuchMethodException: com.blizzard.bnet.push.endpoint.services.PushProperties1.<init>()
OK, I saw a Spring issue that wasn't included until
2.2.1
, so I upgraded. But now I get a different error regarding the nested
SnSClient
class:
Copy code
Parameter 0 of constructor in com.blizzard.bnet.push.endpoint.services.PushServicesProperties1 required a bean of type 'com.blizzard.bnet.push.endpoint.services.PushServicesProperties1$SnsClient' that could not be found.

Failed to load ApplicationContext
No qualifying bean of type 'com.blizzard.bnet.push.endpoint.services.PushServicesProperties1$SnsClient' available
I also added the
@ConstructorBinding
annotation to the inner class
Even tried adding defaults, until the final class is:
Copy code
@ConstructorBinding
@ConfigurationProperties("push1")
data class PushServicesProperties1(val snsClient: SnsClient) {

    @ConstructorBinding
    data class SnsClient(
        val maxConnections: Int = -1,
        val connectionTimeout: Int = 10000,
        val socketTimeout: Int = 10000,
        val proxyHost: String = "",
        val proxyPort: Int? = null
    )
}