Reputation: 874
I want to set my environment variables in ".env" file for spring boot application that's running on EC2 instance, and access them in code. I know i can set environment variables on EC2 like so
export env="dev"
export db.url="xyz"
But i dont want to do this, instead i want to maintain these environment variables in a ".env" file and access them in spring boot application like
@Value("${env}")
public String env;
I'm able to use export and read the env variables but can't get around getting the variables from .env file. I don't want to use shell script either for loading the variables explicitly. Is there a way i can achieve this?
Upvotes: 1
Views: 1003
Reputation: 61
Have you managed to do it locally before deploying to an EC2 instance? Did you try to inject the properties using ".properties" file? It seems like the answer you are looking for. spring-boot-application-configuration
If you manage to do it locally, there is not reason you wouldn't be able to do it in an EC2 instance.
Upvotes: 1