How to access Elastic Beanstalk env var in springboot application

0

We have a springboot server running on Elastic Beanstalk. We want to pull env vars into our .properties file. Currently we have something like

vars=${ENV_VAR} <--- in .properties file

and then in the files something like:

@Value("${vars}")

Private string getvars....

Locally this works just fine. When it's on aws, it seems appears it can't find the variables. We have them set in our EB Instance -> Configuration -> Software -> Environment Variables:

Key = ENV_VAR

Value = valueWeExpect

We have "Spring Cloud AWS Autoconfigure" from maven repo as a dependency, but it still doesn't work. Does anyone know if we are missing a dependency or referencing the variables incorrectly.

mehiatt
질문됨 2년 전565회 조회
1개 답변
0

Try to inject/autowire org.springframework.core.env.Environment & then access it like below,

@Autowired private Environment env; env.getProperty("ENV_VAR");

Hope this helps.

shethap
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠