You can customize the prefix used by declaring the following beans in your configuration:
@Bean fun propertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply { setPlaceholderPrefix("%{") }
if you have existing code (such as Spring Boot Drives or @LocalServerPort ) that uses the ${...} syntax, you must declare:
@Bean fun kotlinPropertyConfigurer() = PropertySourcesPlaceholderConfigurer().apply { setPlaceholderPrefix("%{") setIgnoreUnresolvablePlaceholders(true) } @Bean fun defaultPropertyConfigurer() = PropertySourcesPlaceholderConfigurer()
Exiting the dollar, as in @Value("\${some.property}") , is another possible option that does not require an @Bean .
For Spring boot tests configured with @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) , you can use @LocalServerPort instead of @Value("\${local.server.port}") .
@ConfigurationProperties would be a better alternative, especially with Kotlin data classes, but for now you need to use Kotlin classes with a null value of var , since only getter / setter is supported. You can vote for this issue or comment to show your interest in getting support in Spring Boot 2.x.
Sebastien deleuze
source share