@Singleton public class DefaultMagnoliaPropertiesResolver extends Object implements MagnoliaPropertiesResolver
${servername}
: name of the server where the webapp is running, lowercase${webapp}
: the last token in the webapp path (e.g. magnoliaPublic
for a webapp deployed at
tomcat/webapps/magnoliaPublic
)${contextPath}
: the context path of the web application${systemProperty/*}
is replaced with the corresponding system property${env/*}
is replaced with the corresponding environment property}${contextAttribute/*}
is replaced with the corresponding attribute from servlet context${contextParam/*}
is replaced with the corresponding parameters from servlet context${*}
is replaced with the corresponding value looked up from the system properties, the environment
variables, the context attributes and the context parameters in that order.
If no magnolia.initialization.file
context parameter is set a default is assumed, which depends
on the presence of a MAGNOLIA_PROFILE
environment
variable or system property:
MAGNOLIA_PROFILE
is not set DEFAULT_INITIALIZATION_PARAMETER
is used for a default:
<context-param> <param-name>magnolia.initialization.file</param-name> <param-value> WEB-INF/config/${servername}/${contextPath}/magnolia.properties, WEB-INF/config/${servername}/${webapp}/magnolia.properties, WEB-INF/config/${servername}/magnolia.properties, WEB-INF/config/${contextPath}/magnolia.properties, WEB-INF/config/${webapp}/magnolia.properties, WEB-INF/config/default/magnolia.properties, WEB-INF/config/magnolia.properties" </param-value> </context-param>If
MAGNOLIA_PROFILE
is set PROFILE_INITIALIZATION_PARAMETER
is used for a default:
<context-param> <param-name>magnolia.initialization.file</param-name> <param-value> WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties," WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties," WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia.properties," WEB-INF/config/shared/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties," WEB-INF/config/shared/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties," WEB-INF/config/shared/magnolia.properties," WEB-INF/config/default/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties," WEB-INF/config/default/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties," WEB-INF/config/default/magnolia.properties," </param-value> </context-param>
Using the ${servername}
and ${webapp}
properties you can easily bundle in the same webapp
different set of configurations which are automatically applied depending on the server name (useful for switching
between development, test and production instances where the repository configuration need to be different) or the
webapp name (useful to bundle both the public and admin log4j/jndi/bootstrap configuration in the same war).
The values for the placeholders are provided by MagnoliaInitPaths
. By default the initializer will try to
search for the file in different location with different combination of ${servername}
, ${contextPath}
and ${webapp}
in the following order of precedence:
WEB-INF/config/${servername}/${contextPath}/magnolia.properties
WEB-INF/config/${servername}/${webapp}/magnolia.properties
WEB-INF/config/${servername}/magnolia.properties
WEB-INF/config/${contextPath}/magnolia.properties
WEB-INF/config/${webapp}/magnolia.properties
WEB-INF/config/default/magnolia.properties
WEB-INF/config/magnolia.properties
Deprecation note: this configuration mode is deprecated and will be replaced by profile directories in future versions. See the following section.
Alternatively, when the MAGNOLIA_PROFILE
system property or environment variable is set, its value is used to
locate a directory at code WEB_INF/config/${MAGNOLIA_PROFILE}
. Property files in that directory, the
WEB-INF/config/shared
directory and the WEB-INF/config/default
directory are resolved in the
following order of precedence:
WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties
WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties
WEB-INF/config/${MAGNOLIA_PROFILE}/magnolia.properties
WEB-INF/config/shared/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties
WEB-INF/config/shared/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties
WEB-INF/config/shared/magnolia.properties
WEB-INF/config/default/magnolia_${MAGNOLIA_INSTANCE_TYPE}_${MAGNOLIA_STAGE}.properties
WEB-INF/config/default/magnolia_${MAGNOLIA_INSTANCE_TYPE}.properties
WEB-INF/config/default/magnolia.properties
Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX
Context attribute prefix, to obtain a property definition like ${contextAttribute/property}, that can refer to
any context attribute.
|
static String |
CONTEXT_PARAM_PLACEHOLDER_PREFIX
Context parameter prefix, to obtain a property definition like ${contextParam/property}, that can refer to any
context parameter.
|
protected static String |
DEFAULT_INITIALIZATION_PARAMETER
Deprecated.
Use
PROFILE_INITIALIZATION_PARAMETER instead |
static String |
ENV_PROPERTY_PLACEHOLDER_PREFIX
System property prefix, to obtain a property definition like ${systemProperty/property}, that can refer to any
System property.
|
protected static String |
MAGNOLIA_INITIALIZATION_FILE
Context parameter name.
|
protected static String |
MAGNOLIA_PROFILE_ENV
Enable profile based configuration by setting
MAGNOLIA_PROFILE . |
protected static String |
PROFILE_INITIALIZATION_PARAMETER
Default value for the MAGNOLIA_INITIALIZATION_FILE parameter in profile based configuration.
|
static String |
SYSTEM_PROPERTY_PLACEHOLDER_PREFIX
System property prefix, to obtain a property definition like ${systemProperty/property}, that can refer to any
System property.
|
Constructor and Description |
---|
DefaultMagnoliaPropertiesResolver(javax.servlet.ServletContext context,
MagnoliaInitPaths initPaths)
|
DefaultMagnoliaPropertiesResolver(javax.servlet.ServletContext context,
MagnoliaInitPaths initPaths,
SystemPropertySource systemPropertySource,
EnvironmentPropertySource environmentPropertySource) |
Modifier and Type | Method and Description |
---|---|
protected String |
getConfigurationProfile() |
protected String |
getInitParameter(javax.servlet.ServletContext ctx,
String name,
String defaultValue) |
protected List<String> |
getLocations()
Used in tests, potentially in subclasses.
|
List<PropertySource> |
getSources()
Returns the paths to load, TODO: in which order ?
|
public static final String CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX
public static final String CONTEXT_PARAM_PLACEHOLDER_PREFIX
public static final String SYSTEM_PROPERTY_PLACEHOLDER_PREFIX
public static final String ENV_PROPERTY_PLACEHOLDER_PREFIX
protected static final String MAGNOLIA_INITIALIZATION_FILE
@Deprecated protected static final String DEFAULT_INITIALIZATION_PARAMETER
PROFILE_INITIALIZATION_PARAMETER
insteadMAGNOLIA_PROFILE
is set.protected static final String PROFILE_INITIALIZATION_PARAMETER
MAGNOLIA_PROFILE
is set.protected static final String MAGNOLIA_PROFILE_ENV
MAGNOLIA_PROFILE
.@Inject public DefaultMagnoliaPropertiesResolver(javax.servlet.ServletContext context, MagnoliaInitPaths initPaths, SystemPropertySource systemPropertySource, EnvironmentPropertySource environmentPropertySource)
@Deprecated public DefaultMagnoliaPropertiesResolver(javax.servlet.ServletContext context, MagnoliaInitPaths initPaths)
protected String getConfigurationProfile()
protected String getInitParameter(javax.servlet.ServletContext ctx, String name, String defaultValue)
public List<PropertySource> getSources()
MagnoliaPropertiesResolver
getSources
in interface MagnoliaPropertiesResolver
Copyright © 2003–2020 Magnolia International Ltd.. All rights reserved.