mr.nothing mr.nothing - 1 month ago 6x
Java Question

Spring @Value annotation

I'm Spring newbie and I'm wondering what are prerequisites/conditions of using @Value annotation in Spring?

What I have for now is a Token class which has hardcoded secret key as a field. What I'm trying to do is to move this secret key to config file to eliminate hardcoding but for some reason the following is not working.

public class Token {
//...some code

private String key;

//...some code

Maybe there is any standard technique to solving this type of tasks.

Thanks for help!

p.s. I have
file which contains


Injecting dependencies and values only works on objects that are managed by Spring - when you manually create an object using new, for example by doing new Token(), then Spring cannot process the object to inject dependencies and values.

The Token object must be a Spring bean for this to work.