Reputation: 29537
My Spring Boot app will have 4 different environments:
When a new user registers for my app, the backend sends them an email to verify their address/account. In this email there will be a link; the user clicks the link which verifies them in the database and allows them to now login and use the app.
These links of course have to have the environment built into them:
http://localhost:9200/v1/data/accounts/verify?vt=12345
http://dev.myapp.example.com/v1/data/accounts/verify?vt=12345
http://uat.myapp.example.com/v1/data/accounts/verify?vt=12345
http://myapp.example.com/v1/data/accounts/verify?vt=12345
In all three environments, the hostname + port are different. Locally I specify localhost:9200
(both localhost + port). Non-locally I don't need to specify port because the app will be running on nodes behind a load balancer. In production I don't need an environment-specific subdomain like dev
or uat
.
In order for my emails to work correctly in all 4 environments, I need to set an environment variable that is then used by my email generator to generate links correctly.
I could use something homegrown, such as a custom property in application.properties
like emailDomain
, and set the property different in each environment's properties file.
But I feel like the smart folks that make up the Spring Boot community have probably already solved this problem for me...have they? Is there already a Spring Boot app property I can set that will take care of all this for me?
Upvotes: 1
Views: 10175
Reputation: 44685
In the comments, I read that your main concern is being able to update the property without having to modify your .JAR/.WAR or changing some code.
This is possible since you can externalize your Spring boot configuration. If you check the Externalized Configuration docs, you can see that it looks for properties within:
- OS environment variables.
...
- Profile-specific application properties outside of your packaged jar (
application-{profile}.properties
and YAML variants)- Profile-specific application properties packaged inside your jar (
application-{profile}.properties
and YAML variants)- Application properties outside of your packaged jar (
application.properties
and YAML variants).- Application properties packaged inside your jar (
application.properties
and YAML variants).
So, ideally, you can put an application.properties
file next to your JAR, and update the properties in that file depending on the environment you run on.
Upvotes: 2