We have 4 servers that run JBOSS AS7:
On each jboss, a simple webapp will run. This webapp will use spring and requires some properties to be set like:
webservice.endpoint=interface.url.com
webservice.port=7676
The properties will differ for each environment. The way we handle this at this moment is as follows:
I have a JAR file with a single file in it, config.properties. This property file contains all my properties. I turn this jar into a global jboss module and configure it in my domain.xml
(or standalone.xml
) to be included. This works, because spring can access the properties when making beans.
However, it seems overly complicated to turn properties into a jar, into a module. I was thinking I should maybe use system properties to achieve this? My question is: is this a good place to put all the environment specific, application specific properties? Will they be loaded into the JVM so everyone can access them at will (especially Spring, which uses the ${myProperty}
notation to access properties). Additionally, when I add properties using the console in my browser, were are they stored? I cannot see them in domain.xml
or host.xml
.
if you go with the JAR solution : - use an unique classifier for each environments. You will have x properties files : dev_config.properties / test_config.properties, etc...
this way you can just set an unique JAVA_OPTS that set the environment in which you are. then you get the right properties file :
using : System.getenv("ENV")
or System.getProperty("ENV")
if ("DEV".Equals(System.getenv("ENV"))
here you load ==> the dev_config.properties
to load the properties into a JAR it is really easy with this maven plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>packaging-deployment_manifests_bundle</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
<configuration>
<descriptors>
<descriptor>descriptors/deployment_manifests_bundle.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
if you go with the environment_variables : I never tried this solution in my projects, I always went with the properties file solution. but if you have just a few variables to set, this could be even quicker... you can access those variables with :
import java.util.Map;
public class EnvMap {
public static void main (String[] args) {
Map<String, String> env = System.getenv();
for (String envName : env.keySet()) {
System.out.format("%s=%s%n",
envName,
env.get(envName));
}
}
}
Adding data in the environments variables can be OK if it is nothing sensitive, like passwords and the likes. It is easier IMO to obfuscate data in a properties file. So if security is at stake, this is a point to consider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With