Home > Net >  How do I set a config property in quarkus kotlin
How do I set a config property in quarkus kotlin

Time:01-08

In quarkus Java you can set a configuration property by defining it in application.properties. This can be used in some class like this:

@ApplicationScoped
public class SomeClass {
    @ConfigProperty(name = "some.config")
    String someConfig;
}

How do you achieve the same in Kotlin?

CodePudding user response:

The one to one conversion to Kotlin would yield:

@ApplicationScoped
open class SomeClass {

    @field:ConfigProperty(name = "some.config")
    lateinit var someConfig: String
}

However, it would look much better if you use constructor injection like so:

@ApplicationScoped
open class SomeClass(@ConfigProperty(name = "some.config") val someConfig: String) {

}

CodePudding user response:

Geoand's answer is correct. What I ended up using was a slightly less verbose version that I personally prefer.

@ApplicationScoped
class SomeClass {
    @ConfigProperty(name = "some.config")
    lateinit var someConfig: String
}
  •  Tags:  
  • Related