-
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 requires class to be mutable in Kotlin #4563
Comments
What's Kotlin specific exactly? |
It is my understanding that in Java we can make the
. . and that the object will be configured using reflection. In Kotlin, this didn't work. The properties had to be mutable. (I'll attach a sample in a moment).
|
No. As I said, in Java you need a regular JavaBean property (public getter/setter). We don't support anything else at the moment and your request is not kotlin specific either (unless I am mistaken). Duplicates #1254 |
Ah, I see! I assumed config objects would naturally lean towards being immutable. 👍 on 1254 for myself as well then :) Thank you. |
@jasperblues Do you have any Kotlin |
Sure: @Component
class TokenAuthenticationProvider : AuthenticationProvider
{
val profileRepo : ProfileRepository
val apiKey : String
//---------------------------------------------------------------------------------------
//MARK: - Constructors
//---------------------------------------------------------------------------------------
@Autowired constructor(profileRepo: ProfileRepository, @Value("\${service.api.apiKey}") apiKey: String)
{
this.profileRepo = profileRepo
this.apiKey = apiKey
}
//etc . . . Unfortunately as |
@jasperblues Could you try with |
@sdeleuze Out of the box, with standard Spring Boot, that does not work. However, I suspect if you changed the |
@jasperblues In fact, using More details on my answer on Stackoverflow. |
@sdeleuze Thank you, sir :) |
Is it possible to get
@ConfiguraitonProperties
to inject a matching constructor? Otherwise in Kotlin it is necessary to declare the configured properties as public and mutable, which is not ideal.Also, in Kotlin, the @value annotation is a little ugly, since "${something}" is a language feature and must be escaped.
I generally love using Spring Boot and Kotlin together - what could be more fun? But things get a little ugly when it comes to external configuration.
The text was updated successfully, but these errors were encountered: