I was trying to externalise my configuration of a class level annotation using allication.yaml. But the spring is not loading it right. Any idea how to do this ?
Here is my Service classI am trying to set
@Service
@DefaultProperties(threadPoolProperties = {
@HystrixProperty(name = "coreSize", value =
"${cyclone.hystrix.lease.thread.coreSize}") })
public class LeaseService {
}
And application.yml
cyclone:
hystrix:
lease:
thread:
coreSize: 10
Getting an error --
java.lang.IllegalArgumentException: bad property value. property name 'coreSize'. Expected int value, actual = ${cyclone.hystrix.lease.thread.coreSize}
I can load the same property using @Value("${cyclone.hystrix.lease.thread.coreSize}"). But not working on the above mentioned case. Any help on how to properly configure this ?
In order to make spring evaluate placeholders you need to register a PropertySourcesPlaceholderConfigurer bean using a static @Bean method when using @Configuration classes as follows:
@Bean
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
According to the JavaDoc:
Specialization of PlaceholderConfigurerSupport that resolves ${...} placeholders within bean definition property values and @Value annotations against the current Spring Environment and its set of PropertySources.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With