PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 5, 2022

[FIXED] How to access Elastic Beanstalk env var in springboot application

 November 05, 2022     amazon-elastic-beanstalk, amazon-web-services, environment-variables, java, spring-boot     No comments   

Issue

We have a springboot/Tomcat server running on Elastic Beanstalk. We want to use the Env vars set in beanstalk in our springboot code. Currently we have something like

Private string getvar = System.getenv("ENV_VAR");
//and have also tried
Private string getvar = System.getProperty("ENV_VAR");

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

Key = ENV_VAR     
Value = valueWeExpect

and I confirmed they are set via cloudShell.

Does anyone know if we are missing a dependency or referencing the variables incorrectly? Is there anything we have to add?


Solution

I get my via

@Autowired
private Environment _env;

_env.getProperty("ENV_VAR")

Environment is org.springframework.core.env.Environment



Answered By - denov
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing