12 factor app config and Java
Asked Answered
R

3

10

I was reading the 12 factor app manifesto http://12factor.net/. The manifesto recommends storing the configuration data for the application in Enviornment variables. Does this mean that properties like the DB username / password, resource URL should be stored as a part of Java Env variables rather than as property files ? Is this a secure way of storing the information ? To me this seems to be a pretty clunky way of storing the information. Are there any best practices / experiences around this that can be shared ?

One option that I can think of is to have a separate configuration service running in the landscape, and use Env property to connect to the config service and then query the config service for further detailed configuration data.

Ridley answered 15/8, 2014 at 16:57 Comment(2)
This seems like it'd be a perfect fit for Programmers.SE rather than here.Cemetery
This question belongs on another site in the Stack Exchange network, but programmers.se is not an option by default.Nereid
M
7

12 factor apps are designed to run on platforms that orchestrate isolated UNIX processes. UNIX processes are configured via environment variables. While property files are a well-established Java convention, UNIX processes are a language-agnostic way to configure processes.

To support multiple configuration methods, a good best practice is to:

  • Read from process environment with System.getenv('CONFIG'), if null
  • Read from property file with properties.getProperty('CONFIG'), if null
  • Fall back to a default value

For more details, see Heroku's instructions on defining config vars for Java apps.

Manganese answered 26/11, 2014 at 2:38 Comment(2)
If you are using an app server (like WAS Liberty) that understands environment variables specified in configuration files, you can do similar processing outside of your application code (the business logic) while remaining inside the produced artifact.Biebel
actually, one of the important things in 12factor is having a single well known configuration source - having both environment and configuration files can be less desirable. IMO having a single well defined configuration source is more important then if it's in the environment or in a (language agnostic) configuration fileGillman
H
1

We can use Spring Centralized Configuration to do that, using centralized configuration we can commit configuration of all of our projects into a single repository and later on while writing build scripts we can override our local configuration from that repository to use that centralised configuration.

By clicking on below link you will find getting started guide to do so

https://spring.io/guides/gs/centralized-configuration/

Hartzke answered 12/10, 2016 at 6:1 Comment(0)
M
1

This piece on How To Implement 12 Factor Configuration In Java maybe helpful: https://blog.codacy.com/12-factor-config-for-java/

It's published by Codacy, the automated code review tool.

Mossy answered 26/11, 2019 at 1:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.