To prevent repeated injections of the same value by creating a non-static field in the class that gets the instance very often, I chose 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; @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 enter the value first as a static integer:
private static Integer value1 = ConfigUtil.getInstance().getValue1();
Florian sager
source share