-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Misleading exception message when unnecesarily declaring properties bean with Spring Beans DSL #22311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Update. Removing bean<CallmeProperties>() from beans definition resolves the problem. So the problem is the misleading exception message. |
I am not sure what is misleading here. One one hand you've enabled component scanning for
It's not the same thing, is it? In this version you're not defining the bean yourself. |
Well, I think I once got error indicating that I redeclared bean (but I may be wrong) so I would say this could be clearer. What I wanted to use in first place was So, maybe I should give up on @SpringBootApplication
class CallmeApp
fun main(){
runApplication<CallmeApp> {
addInitializers(appBeans())
}
}
fun appBeans() = org.springframework.context.support.beans {
bean<CallMeProperties>()
bean {
TestRouter(ref()).testRouter()
}
}
class CallMeProperties(
@Value("\${app.property1}") val property1: String,
@Value("\${app.property2}") val property2: String
) Is this correct? |
Not really no. That sounds overcomplicated to what you had previously.
I have no idea how this led to the above situation. If you This works just fine and is very similar to what you call "traditional way". @SpringBootApplication
@ConfigurationPropertiesScan
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@ConstructorBinding
@ConfigurationProperties(prefix = "callme")
data class CallMeProperties(
var property1: String,
var property2: String
) If you have more questions, please follow-up on StackOverflow or chat with the community on Gitter. |
The changes made for #20798 mean that the error message that is produced has changed, hopefully for the better. With the latest snapshots, the failure looks like this:
|
Uh oh!
There was an error while loading. Please reload this page.
Application with Bean DSL and
@ConstructorBinding
is unable to start due toorg.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pl.app.callme.CallMeProperties#0': @EnableConfigurationProperties or @ConfigurationPropertiesScan must be used to add @ConstructorBinding type pl.app.callme.CallMeProperties
even though both (or one of them) are present.App:
Here's
application.yml
:And
build.gradle.kts
:Full exception:
App written in traditional way works just fine:
application.yml
:The text was updated successfully, but these errors were encountered: