I am novice to java and spring framework. My questions is how to inject OS(ubuntu) environment variable to spring boot bean. What I tried:
@Configuration
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
@Value("${COMPONENT_PARAM_CORS}")
private String COMPONENT_PARAM_CORS;
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/"+COMPONENT_PARAM_CORS);
}
}
export COMPONENT_PARAM_CORS=**
printenv
says me that its present, but when I try to mvn clean install: error occured
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'corsConfig': Injection of autowired dependencies
failed; nested exception is java.lang.IllegalArgumentException: Could not
resolve placeholder 'COMPONENT_PARAM_CORS' in value "${COMPONENT_PARAM_CORS}"
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder
'COMPONENT_PARAM_CORS' in value "${COMPONENT_PARAM_CORS}"
and then my unit test also droped (I am trying to search this error, but all topics is old and uses params from application.properties, but I need to use env var not application.properties)