javaspringproperty-placeholder

Spring injecting property values without @Value annotation


We have been using Spring @Value annotation to inject the property values. We have a convention to name the property names to match the java fields they inject. This bring in unnecessary work that each of config bean's java fields needs to be annotated with @Value.

I'm looking for a way to just annotate the java class with new annotation (let's say ConfigBean) and have some post processor read the property names of such beans and inject the property values automatically.

I'm looking for some pointers on how to go about implementing this property injection without @Value annotation.


Solution

  • you might want to take a look at spring boot's ConfigurationProperties annotation.

    see this link for an example.