public class AppConfig extends Object implements Map<String,String>
environment.properties, where environment is a name of a deployment environment, such as "development",
"staging", "production", etc.
You can also provide a global file, properties from which will be loaded in all environments: global.properties.
In all cases the files need to be on the classpath under directory/package /app_config.
Environment-specific file will have an "environment" part of the file name match to an environment variable called "ACTIVE_ENV".
Such configuration is easy to achieve in Unix shell:
export ACTIVE_ENV=test
If environment variable ACTIVE_ENV is missing, it defaults to "development".
You can also provide an environment as a system property active_env. System property overrides environment
variable ACTIVE_ENV
| Constructor and Description |
|---|
AppConfig() |
| Modifier and Type | Method and Description |
|---|---|
static String |
activeEnv()
Returns current environment name as defined by environment variable
ACTIVE_ENV. |
void |
clear() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,String>> |
entrySet() |
String |
get(Object key) |
static Map<String,String> |
getAllProperties() |
static Property |
getAsProperty(String key)
Returns property instance corresponding to key.
|
static List<String> |
getKeys(String prefix)
Returns all keys that start with a prefix
|
static List<String> |
getProperties(String prefix)
Return all numbered properties with a prefix.
|
static String |
getProperty(String key)
Returns property value for a key.
|
static void |
init() |
boolean |
isEmpty() |
static boolean |
isInDevelopment() |
static boolean |
isInProduction() |
static boolean |
isInStaging() |
static boolean |
isInTestEnv() |
Set<String> |
keySet() |
static String |
p(String key)
Gets property, synonym for
getProperty(String). |
String |
put(String key,
String value) |
void |
putAll(Map<? extends String,? extends String> m) |
String |
remove(Object key) |
int |
size() |
Collection<String> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAllpublic static void init()
public static Property getAsProperty(String key)
key - key for property.public static String getProperty(String key)
key - key of property.null if not found.public static String p(String key)
getProperty(String).key - key of propertypublic boolean containsKey(Object key)
containsKey in interface Map<String,String>public boolean containsValue(Object value)
containsValue in interface Map<String,String>public static String activeEnv()
ACTIVE_ENV.ACTIVE_ENV.public static boolean isInTestEnv()
ACTIVE_ENV is "testenv".public static boolean isInProduction()
ACTIVE_ENV is "production".public static boolean isInDevelopment()
ACTIVE_ENV is "development".public static boolean isInStaging()
ACTIVE_ENV is "staging".public static List<String> getKeys(String prefix)
prefix - prefix for properties.public static List<String> getProperties(String prefix)
prop.1=one
prop.2=two
.. and this method is called:
List props = AppConfig.getProperties("prop");
then the resulting list will have all properties starting from prop.
This method presumes consecutive numbers in the suffix.prefix - prefix of numbered properties.Copyright © 2016 JavaLite. All rights reserved.