-
Notifications
You must be signed in to change notification settings - Fork 40.8k
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
ConfigurationProperties does not work on kotlin components after migration 2.7.3 to 3.0.0 #33509
Comments
Spring Boot 3.0 removed the need for adding If you really want the class to be a bean, you need to make sure there is a @ConfigurationProperties("my-service")
@ConditionalOnProperty("my-service", havingValue = "c")
@Component
data class SomeBean(var customValue: String = "not set") {
@Autowired
constructor() : this("default")
} Or you could just drop the |
As a related note, you should not be using
|
From that doc entry...
Really? Examples on Baeldung also showed it like that.
The problem is that this class is designed for parameter holding. It was also told that this change is an improvement. I do not see it. What was wrong with the previous approach? Why is it better now? And why do I feel lost? Let us say that I do not it to be a real bean - I mean a Component or service. data class SomeBean(var customValue: String = "not set")
@Configuration
@EnableConfigurationProperties
class MyConfig {
@Bean
@ConditionalOnProperty("my-service", havingValue = "c")
@ConfigurationProperties("xyz")
fun someBean() = SomeBean()
} And why there is no exception if it worked previously? |
@philwebb could you please see the comment above? And also, is this approach more or less final, or still possible to change? |
@Azbesciak I'm afraid I don't really understand the sample above so perhaps we can take a step back. What is it that you are trying to achieve by having If so, I'm afraid your approach won't work. If you want to create |
Yes, exactly
but it worked in 2.7... :( |
Nothing has changed in this regard in Spring Boot 3.0 – it has never been possible to use constructor binding when application code is creating the instance. You need to let Spring Boot create the instance for you if you want to use constructor binding. I don't think we really understand what you're trying to do and what worked in 2.7 and does not work in 3.0. To help us to understand, please create a minimal sample that works with 2.7.x and then fails when upgraded to 3.0.x. You can share such a sample with us by pushing it to a separate repository on GitHub or zipping it up and attaching it to this issue. |
@wilkinsona |
Sorry, I should have been clearer about what I was looking for. It was a complete example of the |
@wilkinsona Thank you - is it going to be fixed, or it was a bug previously as I would interpret from @philwebb response? Anyway, I would need to change around 70% of my |
@Azbesciak The sample in #33710 helped me understand the issue better and I've just pushed a fix. 🤞it will also solve your problem. If you want to give it a try, you can try the |
@philwebb Thank you a lot, I also see that the initially reported issue is fixed! Works as expected, thank you for your time and understanding. |
This comment was marked as outdated.
This comment was marked as outdated.
ConfigurationProperties
does not work on kotlin components after migration 2.7.3 to 3.0.0
Did the issue come back? I bumped up from 3.0.2 to 3.1.1 and...
@Component
@ConditionalOnProperty("auth.jwt.external.enabled", havingValue = "true")
@ConfigurationProperties("auth.jwt.external")
data class ExternalJwtTokenParserConfig(
var service: ExternalJwtPaths = ExternalJwtPaths(),
)
data class ExternalJwtPaths(
var uriRoot: String = "",
var path: String = ""
)
|
Hello,
I wanted to see what problems may occur after migration from 2.7.3 to 3.0.0 - my target is to prepare the native application.
So, I have read that there may be some issues with
@ConditionalOnProperty
or@ConditionalOnBean
- I still do not understand why, but ok - wanted to check that.I created the example project, generated from the spring initializr, you may find it there (spring boot version
2.7.3
, to see the issue you need to switch to3.0.0
)https://github.com/Azbesciak/spring-3-configuration-prop-issue
the problem is with the following, which works in 2.7.3
but does not in 3.0.0
java.lang.IllegalStateException: Cannot bind @ConfigurationProperties for bean 'someBean'. Ensure that @ConstructorBinding has not been applied to regular bean
I initially tried with the
@Bean
in service, like belowBut it failed without error, the property was also not set.
BTW I was under the impression that this should work
but it does only when I change the property name in
@ConfigurationProperties
to be outside the scope ofmy-service
(my-service.value
orxyz
would work - in2.7.3
, in3.0.0
does not)I saw #33471, but not sure if it is true. Maybe I miss something?
In spring-attic/spring-native#1679 you made a statement, based on which I thought that in 3.0.0 everything is going to work without any effort. So... is it a bug, or a feature?
The text was updated successfully, but these errors were encountered: