Question

How would you inject a value from a .properties file to a pojo class? What I want to achieve is everytime I get an instance of this class, it will return to me an instance with that value already injected to it. I put it in a .properties file instead of within the java class itself for I'll be needing it for easy change on configuration later.

I'm currently trying adding this annotation @Value("${myfield.name}") on my variable on my pojo class to no avail.

Any help is appreciated. Thanks!

Was it helpful?

Solution

I was able to make this work:

@Value("${myfield.name}")

But you would need to annotate your class with any of @Component, @Service etc. And you would need the property-placeholder tag on your xml ofcourse.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top