• Latest
Stop Using Spring Profiles Per Environment

Stop Using Spring Profiles Per Environment

March 24, 2023
IPHONE 13 PRO  — REVIEW  || Marques Brownlee ||

IPHONE 13 PRO — REVIEW || Marques Brownlee ||

March 26, 2023
Final Fantasy 14 Shoe Line Coming From Puma

New Final Fantasy 16 Trailer Shows Off the World of Valisthea

March 26, 2023
Redmi Note 12S and Note 12 Pro 4G could be on their way as well

Redmi Note 12S and Note 12 Pro 4G could be on their way as well

March 26, 2023
The Steam Deck is Incomplete – SteamOS Software Review

The Steam Deck is Incomplete – SteamOS Software Review

March 26, 2023
Bluetooth 5.0: Explained!

Bluetooth 5.0: Explained!

March 26, 2023
Top 10 MMORPGs With Player Housing In 2023

Top 10 MMORPGs With Player Housing In 2023

March 26, 2023

Which SMARTPHONES Do We Actually Use? 2023 YOUTUBER Edition ft. MKBHD, Linus Tech Tips + More

March 26, 2023
Dark and Darker Removed From Steam Following DMCA Takedown

Dark and Darker Removed From Steam Following DMCA Takedown

March 25, 2023
How to watch March Madness 2023 on iPhone and more

How to watch March Madness 2023 on iPhone and more

March 25, 2023
Animal Crossing: New Horizons Manga Up For Grabs At Free Comic Book Day 2023

Animal Crossing: New Horizons Manga Up For Grabs At Free Comic Book Day 2023

March 25, 2023

TA Team Picks (March 25th)

March 25, 2023
Apple to launch AirPods Pro 2’s USB-C version later this year

Apple to launch AirPods Pro 2’s USB-C version later this year

March 25, 2023
Advertise with us
Sunday, March 26, 2023
Bookmarks
  • Login
  • Register
GetUpdated
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact
No Result
View All Result
GetUpdated
No Result
View All Result
GetUpdated
No Result
View All Result
ADVERTISEMENT

Stop Using Spring Profiles Per Environment

March 24, 2023
in Software Development
Reading Time:3 mins read
0 0
0
Share on FacebookShare on WhatsAppShare on Twitter


Lately, I’ve come across a lot of discussions and articles about Spring’s feature called Profiles that are promoting them as a way to separate environment-specific configurations, which I consider a bad practice.

Common Examples

The typical way profiles are presented is by having multiple configuration files within the resources folder that will be bundled within the application artifact with application-prod.yml like:

Application Prod.

some-resource.address: prod-address
some-resource.username: prod-user
some-resource.password: prod-password

Issues

I hope one can immediately see some of the issues:

  • Applications’ production credentials are committed and available for everyone with access to the repository, which is a very serious security issue.
  • Changing configuration value on a given environment would require recompiling and the creation of a new artifact.
  • The introduction of a new environment would require recompiling and the creation of a new artifact.

Recompilation and release of a new application version without really changing any application logic feels stupid.

Solution

How can this issue be solved?

Well, config values have to be put outside of the application’s artifact and VCS repository as recommended by Twelve-Factor App.

There are at least two ways I have experience:

  1. Having a config file beside application.jar (or specifying spring.config.additional-location) on a given environment overrides only specific keys.
  2. Use environment variables.

In the latter case, config keys are bound with environment variables e.g. some-resource.username <=>SOMERESOURCE_USERNAME.

If a custom key name is needed, an “alias” can be made as:

some-resource.username: ${OTHER_ENV_KEY}

In either case, what’s the need for config files per environment?

All that is needed is a single application.yml file with both internal and external properties required by the application.

These properties can have either empty or default/local values.

some-resource.address:
some-resource.username: username
some-resource.password: ${OTHER_ENV_KEY:123456}

When to Use Profiles

So far, I have never had a need for profiles per environment. 

However, there is one “special” profile that I would not consider an environment configuration file, and that is test the profile located in src/test/resources/. This profile and its corresponding configuration file allow overriding only present keys.

Having application.yml file in the given folder would require providing all config properties defined in the main file (if that’s not an issue, go for it).

To activate this profile, use @ActiveProfiles annotation on test classes.

The only other usage of profiles I can think of is some optional feature config grouping.

One advantage of the profile’s mechanism in configuration files is its ability to merge/override config properties (for details, check Piotr’s TechBlog and his Github playground project). 

If we have some optional feature, which requires a separate set of config attributes that we want to be added only if this feature is active, we could have application-{feature-name}.yml, which can be activated in the main config file via spring.profiles.active/include properties.

For simple feature flagging, I would use @ConditionalOnProperty annotation.

Conclusion

To conclude, don’t store environment-specific configuration inside the application and instead use externalized configuration managed/injected on a given environment.

Note: Please feel free to share your opinion and experience on the usage of profiles for environment-specific configuration files or in general. I might be missing something or made a mistake, and I would like to broaden my knowledge.



Source link

ShareSendTweet
Previous Post

Marques Brownlee & Americus Reed Take on the Branding History of the Sony Walkman

Next Post

Pokémon: Ash’s English Voice Actor Thanks Japanese Voice Actor For 17 Years Of Inspiration

Related Posts

NoSQL vs SQL: What, Where, and How

March 25, 2023
0
0
NoSQL vs SQL: What, Where, and How
Software Development

As a beginner, it is essential to understand the two most commonly used types of databases: SQL and NoSQL. In...

Read more

Top 5 Data Streaming Trends for 2023

March 25, 2023
0
0
Top 5 Data Streaming Trends for 2023
Software Development

Data streaming is one of the most relevant buzzwords in tech to build scalable real-time applications in the cloud and...

Read more
Next Post
Pokémon: Ash’s English Voice Actor Thanks Japanese Voice Actor For 17 Years Of Inspiration

Pokémon: Ash's English Voice Actor Thanks Japanese Voice Actor For 17 Years Of Inspiration

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

© 2021 GetUpdated – MW.

  • About
  • Advertise
  • Privacy & Policy
  • Terms & Conditions
  • Contact

No Result
View All Result
  • Game Updates
  • Mobile Gaming
  • Playstation News
  • Xbox News
  • Switch News
  • MMORPG
  • Game News
  • IGN
  • Retro Gaming
  • Tech News
  • Apple Updates
  • Jailbreak News
  • Mobile News
  • Software Development
  • Photography
  • Contact

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?