To prevent ever repeating injections of the same value making a field non-static in a class that gets instantiated very often, I preferred to create a simple Singleton ConfigUtil as a workaround:
package de.agitos.app.util;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Value;
/**
* Helper class to get injected configuration values from static methods
*
* @author Florian Sager
*
*/
@Configurable
public class ConfigUtil {
private static ConfigUtil instance = new ConfigUtil();
public static ConfigUtil getInstance() {
return instance;
}
private @Value("${my.value1}") Integer value1;
public Integer getValue1() {
return value1;
}
}
Inside the class I tried to inject the value first as a static Integer:
private static Integer value1 = ConfigUtil.getInstance().getValue1();