I'd like to get the value of @Value("${myVar}") from ApplicationContext. How to do it? Using Spring 5.3.14.
CodePudding user response:
You can obtain the value of a property using the Environment API:
@Autowired
private Environment env;
...
var x = env.getProperty("myVar");
You can also get the Environment from ConfigurableApplicationContext.
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/ConfigurableApplicationContext.html
