Hugh Lee Hugh Lee - 4 months ago 29x
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.