Can I use Spring @Value annotation to read and write property values โโof a custom class type?
For instance:
@Component @PropertySource("classpath:/data.properties") public class CustomerService { @Value("${data.isWaiting:#{false}}") private Boolean isWaiting;
UNITED SOLUTION
Here's how I did it using the Spring 4.x API ...
Created a new PropertyEditorSupport class for the Customer class:
public class CustomerPropertiesEditor extends PropertyEditorSupport {
Then in the ApplicationConfig application class:
@Bean public CustomEditorConfigurer customEditorConfigurer() { Map<Class<?>, Class<? extends PropertyEditor>> customEditors = new HashMap<Class<?>, Class<? extends PropertyEditor>>(1); customEditors.put(Customer.class, CustomerPropertiesEditor.class); CustomEditorConfigurer configurer = new CustomEditorConfigurer(); configurer.setCustomEditors(customEditors); return configurer; }
Cheers PM
source share