@ -394,6 +394,48 @@ class YourBean {
@@ -394,6 +394,48 @@ class YourBean {
}
----
=== Injecting configuration properties
In Java, you can inject configuration properties using annotations like `@Value("${property}")`,
however in Kotlin `$` is a reserved character that is used for https://kotlinlang.org/docs/reference/idioms.html#string-interpolation[string interpolation].
In order to use `@Value` in Kotlin, you have to escape the `$` character by writing `@Value("\${property}")`.
As an alternative, you can also customize the properties placeholder prefix by declaring
the following beans in your configuration:
[source,kotlin]
----
@Bean
fun propertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply {
setPlaceholderPrefix("%{")
}
----
If you have any existing code (like Spring Boot actuators or `@LocalServerPort`) that is
using the `${...}` syntax, you should declare the following beans in your configuration:
[source,kotlin]
----
@Bean
fun kotlinPropertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply {
setPlaceholderPrefix("%{")
setIgnoreUnresolvablePlaceholders(true)
}
@Bean
fun defaultPropertyConfigurer() = PropertySourcesPlaceholderConfigurer()
----
[NOTE]
====
If you are using Spring Boot, you would probably be interested in using