You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/docs/asciidoc/kotlin.adoc
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -394,6 +394,48 @@ class YourBean {
394
394
}
395
395
----
396
396
397
+
=== Injecting configuration properties
398
+
399
+
In Java, you can inject configuration properties using annotations like `@Value("${property}")`,
400
+
however in Kotlin `$` is a reserved character that is used for https://kotlinlang.org/docs/reference/idioms.html#string-interpolation[string interpolation].
401
+
402
+
In order to use `@Value` in Kotlin, you have to escape the `$` character by writing `@Value("\${property}")`.
403
+
404
+
As an alternative, you can also customize the properties placeholder prefix by declaring
405
+
the following beans in your configuration:
406
+
407
+
[source,kotlin]
408
+
----
409
+
@Bean
410
+
fun propertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply {
411
+
setPlaceholderPrefix("%{")
412
+
}
413
+
----
414
+
415
+
If you have any existing code (like Spring Boot actuators or `@LocalServerPort`) that is
416
+
using the `${...}` syntax, you should declare the following beans in your configuration:
417
+
418
+
[source,kotlin]
419
+
----
420
+
@Bean
421
+
fun kotlinPropertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply {
422
+
setPlaceholderPrefix("%{")
423
+
setIgnoreUnresolvablePlaceholders(true)
424
+
}
425
+
426
+
@Bean
427
+
fun defaultPropertyConfigurer() = PropertySourcesPlaceholderConfigurer()
428
+
----
429
+
430
+
[NOTE]
431
+
====
432
+
If you are using Spring Boot, you would probably be interested in using
0 commit comments