I have spring boot application which is referring to Framework jar( Framework jar are common library jar's which are required by all microservices )
In framework jar i have used @Value annotation to read the config.
@Value("${isxyzFeatureEnabled}")
private static String isFeatureEnabled;
This value is not getting set when the application starts. However if i move this class to Individual microservice then it works.
I need to keep this class in framework as it will be reused by many microservices.
Any suggestions how can i resolve this.
CodePudding user response:
Your variable is static. Unfortunately, "Spring doesn't support @Value on static fields."
Try this solution:
@RestController
public class PropertyController {
@Value("${name}")
private String name;
private static String NAME_STATIC;
@Value("${name}")
public void setNameStatic(String name){
PropertyController.NAME_STATIC = name;
}
}
More info about that: https://www.baeldung.com/spring-inject-static-field