Spring – Inject value into static variables

Spring doesn’t allow to inject value into static variables, for example: import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class GlobalValue { @Value("${mongodb.db}") public static String DATABASE; } If you print out the GlobalValue.DATABASE, a null will be displayed. GlobalValue.DATABASE = null Solution To fix it, create a “none static setter” to assign the injected value for …

Read more