Hugh Lee Hugh Lee - 8 months ago 76
Java Question

An alternative to @Value annotation in static function

It's not possible to use

on a static variable.

static private int someValue;

static public void useValue() {

When I do this,
is printed. So what is a good alternative to this?


Spring inject noting in static field (by default).

So you have two alternatives:

  • (the better one) make the field non static
  • (the ugly hack) add an none static setter which writes in the static field, and add the @Value annotation to the setter.