RESOLVED - issue SPR-4661: Improve context-property-placeholder configurability
Added new features to property override and placeholders (order, locations, system-properties-mode, ignore-*)
This commit is contained in:
parent
c63cdb2444
commit
a29253f2ca
|
|
@ -28,6 +28,7 @@ import org.springframework.util.StringUtils;
|
|||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Arjen Poutsma
|
||||
* @author Dave Syer
|
||||
* @since 2.5.2
|
||||
*/
|
||||
abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
||||
|
|
@ -44,10 +45,28 @@ abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingl
|
|||
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
|
||||
builder.addPropertyValue("locations", locations);
|
||||
}
|
||||
|
||||
String propertiesRef = element.getAttribute("properties-ref");
|
||||
if (StringUtils.hasLength(propertiesRef)) {
|
||||
builder.addPropertyReference("properties", propertiesRef);
|
||||
}
|
||||
|
||||
String fileEncoding = element.getAttribute("file-encoding");
|
||||
if (StringUtils.hasLength(fileEncoding)) {
|
||||
builder.addPropertyReference("fileEncoding", fileEncoding);
|
||||
}
|
||||
|
||||
String order = element.getAttribute("order");
|
||||
if (StringUtils.hasLength(order)) {
|
||||
builder.addPropertyValue("order", Integer.valueOf(order));
|
||||
}
|
||||
|
||||
builder.addPropertyValue("ignoreResourceNotFound",
|
||||
Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));
|
||||
|
||||
builder.addPropertyValue("localOverride",
|
||||
Boolean.valueOf(element.getAttribute("local-override")));
|
||||
|
||||
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,11 +19,13 @@ package org.springframework.context.config;
|
|||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
|
||||
/**
|
||||
* Parser for the <context:property-override/> element.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @since 2.5.2
|
||||
*/
|
||||
class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
||||
|
|
@ -32,5 +34,14 @@ class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDe
|
|||
protected Class getBeanClass(Element element) {
|
||||
return PropertyOverrideConfigurer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
super.doParse(element, builder);
|
||||
builder.addPropertyValue("ignoreInvalidKeys",
|
||||
Boolean.valueOf(element.getAttribute("ignore-unresolvable")));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,11 +19,14 @@ package org.springframework.context.config;
|
|||
import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Parser for the <context:property-placeholder/> element.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @since 2.5
|
||||
*/
|
||||
class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
||||
|
|
@ -32,5 +35,20 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBea
|
|||
protected Class getBeanClass(Element element) {
|
||||
return PropertyPlaceholderConfigurer.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doParse(Element element, BeanDefinitionBuilder builder) {
|
||||
|
||||
super.doParse(element, builder);
|
||||
|
||||
builder.addPropertyValue("ignoreUnresolvablePlaceholders",
|
||||
Boolean.valueOf(element.getAttribute("ignore-unresolvable")));
|
||||
|
||||
String systemPropertiesModeName = element.getAttribute("system-properties-mode");
|
||||
if (StringUtils.hasLength(systemPropertiesModeName)) {
|
||||
builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_"+systemPropertiesModeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/context" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
targetNamespace="http://www.springframework.org/schema/context" elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
<xsd:schema xmlns="http://www.springframework.org/schema/context"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||
targetNamespace="http://www.springframework.org/schema/context"
|
||||
elementFormDefault="qualified" attributeFormDefault="unqualified">
|
||||
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans" schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-3.0.xsd"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"
|
||||
schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd" />
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"
|
||||
schemaLocation="http://www.springframework.org/schema/tool/spring-tool-3.0.xsd" />
|
||||
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
|
@ -17,6 +19,75 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
|
||||
<xsd:complexType name="propertyPlaceholder">
|
||||
<xsd:attribute name="location" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The location of the properties file to resolve placeholders against, as a Spring
|
||||
resource location: a URL, a "classpath:" pseudo URL, or a relative file path.
|
||||
Multiple locations may be specified, separated by commas. If neither location nor properties-ref is
|
||||
specified, placeholders will be resolved against system properties.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="properties-ref" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:java.util.Properties"><![CDATA[
|
||||
The bean name of a Java Properties object that will be used for property substitution.
|
||||
If neither location nor properties-ref is specified, placeholders will be resolved against system properties.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="file-encoding" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies the encoding to use for parsing properties files. Default is none,
|
||||
using the java.util.Properties default encoding. Only applies to classic
|
||||
properties files, not to XML files.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="order" type="xsd:integer">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies the order for this placeholder configurer. If more than one is present in a context
|
||||
the order can be important since the first one to be match a placeholder will win. Often used
|
||||
in conjunction with
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignore-resource-not-found" type="xsd:boolean"
|
||||
default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies if failure to find the property resource location should be ignored. Default
|
||||
is "false", meaning that if there is no file in the location specified an exception will
|
||||
be raised at runtime.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="ignore-unresolvable" type="xsd:boolean"
|
||||
default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies if failure to find the property value to replace a key should be ignored. Default
|
||||
is "false", meaning that this placeholder configurer will raise an exception if it cannot resolve
|
||||
a key. Set to "true" to allow the configurer to pass on the key to any others in
|
||||
the context that have not yet visited the key in question.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="local-override" type="xsd:boolean"
|
||||
default="false">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Specifies whether local properties override properties from files. Default
|
||||
is "false": Properties from files override local defaults.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
|
||||
<xsd:element name="property-placeholder">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
|
|
@ -26,29 +97,25 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
|
||||
<tool:exports
|
||||
type="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="location" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The location of the properties file to resolve placeholders against, as a Spring
|
||||
resource location: a URL, a "classpath:" pseudo URL, or a relative file path.
|
||||
Multiple locations may be specified, separated by commas. If neither location nor properties-ref is
|
||||
specified, placeholders will be resolved against system properties.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="properties-ref" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:java.util.Properties"><![CDATA[
|
||||
The bean name of a Java Properties object that will be used for property substitution.
|
||||
If neither location nor properties-ref is specified, placeholders will be resolved against system properties.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="propertyPlaceholder">
|
||||
<xsd:attribute name="system-properties-mode" default="FALLBACK">
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="NEVER"/>
|
||||
<xsd:enumeration value="FALLBACK"/>
|
||||
<xsd:enumeration value="OVERRIDE"/>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
|
@ -60,27 +127,15 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="org.springframework.beans.factory.config.PropertyOverrideConfigurer"/>
|
||||
<tool:exports
|
||||
type="org.springframework.beans.factory.config.PropertyOverrideConfigurer" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="location" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The location of the properties file to read property overrides from, as a Spring
|
||||
resource location: a URL, a "classpath:" pseudo URL, or a relative file path.
|
||||
Multiple locations may be specified, separated by commas.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="properties-ref" type="xsd:string">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:java.util.Properties"><![CDATA[
|
||||
The bean name of a Java Properties object that will be used for property overrides.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="propertyPlaceholder" />
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
|
||||
|
|
@ -123,14 +178,16 @@
|
|||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="include-filter" type="filterType" minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="include-filter" type="filterType"
|
||||
minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Controls which eligible types to include for component scanning.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
<xsd:element name="exclude-filter" type="filterType" minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:element name="exclude-filter" type="filterType"
|
||||
minOccurs="0" maxOccurs="unbounded">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Controls which eligible types to exclude for component scanning.
|
||||
|
|
@ -138,7 +195,8 @@
|
|||
</xsd:annotation>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="base-package" type="xsd:string" use="required">
|
||||
<xsd:attribute name="base-package" type="xsd:string"
|
||||
use="required">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The comma-separated list of packages to scan for annotated components.
|
||||
|
|
@ -152,7 +210,8 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="use-default-filters" type="xsd:boolean" default="true">
|
||||
<xsd:attribute name="use-default-filters" type="xsd:boolean"
|
||||
default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service,
|
||||
|
|
@ -160,7 +219,8 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="annotation-config" type="xsd:boolean" default="true">
|
||||
<xsd:attribute name="annotation-config" type="xsd:boolean"
|
||||
default="true">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Indicates whether the implicit annotation post-processors should be enabled. Default is "true".
|
||||
|
|
@ -174,8 +234,9 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:expected-type type="java.lang.Class"/>
|
||||
<tool:assignable-to type="org.springframework.beans.factory.support.BeanNameGenerator"/>
|
||||
<tool:expected-type type="java.lang.Class" />
|
||||
<tool:assignable-to
|
||||
type="org.springframework.beans.factory.support.BeanNameGenerator" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -188,8 +249,9 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:expected-type type="java.lang.Class"/>
|
||||
<tool:assignable-to type="org.springframework.context.annotation.ScopeMetadataResolver"/>
|
||||
<tool:expected-type type="java.lang.Class" />
|
||||
<tool:assignable-to
|
||||
type="org.springframework.context.annotation.ScopeMetadataResolver" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -203,9 +265,9 @@
|
|||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="no"/>
|
||||
<xsd:enumeration value="interfaces"/>
|
||||
<xsd:enumeration value="targetClass"/>
|
||||
<xsd:enumeration value="no" />
|
||||
<xsd:enumeration value="interfaces" />
|
||||
<xsd:enumeration value="targetClass" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
|
|
@ -238,7 +300,8 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="org.springframework.instrument.classloading.LoadTimeWeaver"/>
|
||||
<tool:exports
|
||||
type="org.springframework.instrument.classloading.LoadTimeWeaver" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -250,8 +313,9 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:expected-type type="java.lang.Class"/>
|
||||
<tool:assignable-to type="org.springframework.instrument.classloading.LoadTimeWeaver"/>
|
||||
<tool:expected-type type="java.lang.Class" />
|
||||
<tool:assignable-to
|
||||
type="org.springframework.instrument.classloading.LoadTimeWeaver" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -290,7 +354,8 @@
|
|||
|
||||
<xsd:element name="spring-configured">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
|
||||
<xsd:documentation
|
||||
source="java:org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
|
||||
<![CDATA[
|
||||
Signals the current application context to apply dependency injection
|
||||
to non-managed classes that are instantiated outside of the Spring bean
|
||||
|
|
@ -298,13 +363,14 @@
|
|||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string"/>
|
||||
<xsd:restriction base="xsd:string" />
|
||||
</xsd:simpleType>
|
||||
</xsd:element>
|
||||
|
||||
<xsd:element name="mbean-export">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.jmx.export.annotation.AnnotationMBeanExporter"><![CDATA[
|
||||
<xsd:documentation
|
||||
source="java:org.springframework.jmx.export.annotation.AnnotationMBeanExporter"><![CDATA[
|
||||
Activates default exporting of MBeans by detecting standard MBeans in the Spring
|
||||
context as well as @ManagedResource annotations on Spring-defined beans.
|
||||
|
||||
|
|
@ -313,7 +379,8 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="org.springframework.jmx.export.annotation.AnnotationMBeanExporter"/>
|
||||
<tool:exports
|
||||
type="org.springframework.jmx.export.annotation.AnnotationMBeanExporter" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -346,9 +413,9 @@
|
|||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:NMTOKEN">
|
||||
<xsd:enumeration value="failOnExisting"/>
|
||||
<xsd:enumeration value="ignoreExisting"/>
|
||||
<xsd:enumeration value="replaceExisting"/>
|
||||
<xsd:enumeration value="failOnExisting" />
|
||||
<xsd:enumeration value="ignoreExisting" />
|
||||
<xsd:enumeration value="replaceExisting" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
|
|
@ -357,7 +424,8 @@
|
|||
|
||||
<xsd:element name="mbean-server">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation source="java:org.springframework.jmx.support.MBeanServerFactoryBean"><![CDATA[
|
||||
<xsd:documentation
|
||||
source="java:org.springframework.jmx.support.MBeanServerFactoryBean"><![CDATA[
|
||||
Exposes a default MBeanServer for the current platform.
|
||||
Autodetects WebLogic 9+, WebSphere 6.1+ and the JDK 1.5+ platform MBeanServer.
|
||||
|
||||
|
|
@ -366,7 +434,7 @@
|
|||
]]></xsd:documentation>
|
||||
<xsd:appinfo>
|
||||
<tool:annotation>
|
||||
<tool:exports type="javax.management.MBeanServer"/>
|
||||
<tool:exports type="javax.management.MBeanServer" />
|
||||
</tool:annotation>
|
||||
</xsd:appinfo>
|
||||
</xsd:annotation>
|
||||
|
|
@ -403,11 +471,11 @@
|
|||
</xsd:annotation>
|
||||
<xsd:simpleType>
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="annotation"/>
|
||||
<xsd:enumeration value="assignable"/>
|
||||
<xsd:enumeration value="aspectj"/>
|
||||
<xsd:enumeration value="regex"/>
|
||||
<xsd:enumeration value="custom"/>
|
||||
<xsd:enumeration value="annotation" />
|
||||
<xsd:enumeration value="assignable" />
|
||||
<xsd:enumeration value="aspectj" />
|
||||
<xsd:enumeration value="regex" />
|
||||
<xsd:enumeration value="custom" />
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
</xsd:attribute>
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package org.springframework.context.config;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -31,30 +32,76 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
|||
|
||||
/**
|
||||
* @author Arjen Poutsma
|
||||
* @author Dave Syer
|
||||
* @since 2.5.6
|
||||
*/
|
||||
public class ContextNamespaceHandlerTests {
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Before
|
||||
public void createAppContext() {
|
||||
applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests.xml", getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholder() throws Exception {
|
||||
Map beans = applicationContext.getBeansOfType(PropertyPlaceholderConfigurer.class);
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-replace.xml", getClass());
|
||||
Map<String, PropertyPlaceholderConfigurer> beans = applicationContext
|
||||
.getBeansOfType(PropertyPlaceholderConfigurer.class);
|
||||
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
|
||||
String s = (String) applicationContext.getBean("string");
|
||||
assertEquals("No properties replaced", "bar", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderSystemProperties() throws Exception {
|
||||
String value = System.setProperty("foo", "spam");
|
||||
try {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-system.xml", getClass());
|
||||
Map<String, PropertyPlaceholderConfigurer> beans = applicationContext
|
||||
.getBeansOfType(PropertyPlaceholderConfigurer.class);
|
||||
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
|
||||
String s = (String) applicationContext.getBean("string");
|
||||
assertEquals("No properties replaced", "spam", s);
|
||||
} finally {
|
||||
if (value!=null) {
|
||||
System.setProperty("foo", value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderLocation() throws Exception {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-location.xml", getClass());
|
||||
Map<String, PropertyPlaceholderConfigurer> beans = applicationContext
|
||||
.getBeansOfType(PropertyPlaceholderConfigurer.class);
|
||||
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
|
||||
String s = (String) applicationContext.getBean("foo");
|
||||
assertEquals("No properties replaced", "bar", s);
|
||||
s = (String) applicationContext.getBean("bar");
|
||||
assertEquals("No properties replaced", "foo", s);
|
||||
s = (String) applicationContext.getBean("spam");
|
||||
assertEquals("No properties replaced", "maps", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderIgnored() throws Exception {
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-replace-ignore.xml", getClass());
|
||||
Map<String, PropertyPlaceholderConfigurer> beans = applicationContext
|
||||
.getBeansOfType(PropertyPlaceholderConfigurer.class);
|
||||
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
|
||||
String s = (String) applicationContext.getBean("string");
|
||||
assertEquals("Properties replaced", "${bar}", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyOverride() throws Exception {
|
||||
Map beans = applicationContext.getBeansOfType(PropertyOverrideConfigurer.class);
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
||||
"contextNamespaceHandlerTests-override.xml", getClass());
|
||||
Map<String, PropertyOverrideConfigurer> beans = applicationContext
|
||||
.getBeansOfType(PropertyOverrideConfigurer.class);
|
||||
assertFalse("No PropertyOverrideConfigurer found", beans.isEmpty());
|
||||
Date date = (Date) applicationContext.getBean("date");
|
||||
assertEquals("No properties overriden", 42, date.getMinutes());
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
assertEquals("No properties overriden", 42, calendar.get(Calendar.MINUTE));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<context:property-placeholder
|
||||
location="classpath:/org/springframework/context/config/test-*.properties, classpath:/org/springframework/context/config/empty-*.properties, classpath:/org/springframework/context/config/missing-*.properties" />
|
||||
|
||||
<bean id="foo" class="java.lang.String">
|
||||
<constructor-arg value="${foo}" />
|
||||
</bean>
|
||||
|
||||
<bean id="bar" class="java.lang.String">
|
||||
<constructor-arg value="${bar}" />
|
||||
</bean>
|
||||
|
||||
<bean id="spam" class="java.lang.String">
|
||||
<constructor-arg value="${spam}" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<util:properties id="overrideProps">
|
||||
<prop key="date.minutes">42</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-override properties-ref="overrideProps" order="1" />
|
||||
|
||||
<bean id="date" class="java.util.Date">
|
||||
<property name="minutes" value="10"/>
|
||||
</bean>
|
||||
|
||||
<context:property-override location="not/here" ignore-resource-not-found="true" order="2"/>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<util:properties id="placeholderProps">
|
||||
<prop key="foo">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="placeholderProps" ignore-unresolvable="true"/>
|
||||
|
||||
<bean id="string" class="java.lang.String">
|
||||
<constructor-arg value="${bar}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -2,26 +2,23 @@
|
|||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<util:properties id="placeholderProps">
|
||||
<prop key="foo">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="placeholderProps"/>
|
||||
<util:properties id="emptyProps"/>
|
||||
|
||||
<context:property-placeholder properties-ref="placeholderProps" order="2"/>
|
||||
|
||||
<context:property-placeholder properties-ref="emptyProps" order="1" ignore-unresolvable="true"/>
|
||||
|
||||
<context:property-placeholder location="not/here" ignore-resource-not-found="true" order="2"/>
|
||||
|
||||
<bean id="string" class="java.lang.String">
|
||||
<constructor-arg value="${foo}"/>
|
||||
</bean>
|
||||
|
||||
<util:properties id="overrideProps">
|
||||
<prop key="date.minutes">42</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-override properties-ref="overrideProps"/>
|
||||
|
||||
<bean id="date" class="java.util.Date">
|
||||
<property name="minutes" value="10"/>
|
||||
</bean>
|
||||
</beans>
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||
|
||||
<util:properties id="placeholderProps">
|
||||
<prop key="foo">bar</prop>
|
||||
</util:properties>
|
||||
|
||||
<context:property-placeholder properties-ref="placeholderProps" system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<bean id="string" class="java.lang.String">
|
||||
<constructor-arg value="${foo}"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
bar=foo
|
||||
spam=maps
|
||||
|
|
@ -0,0 +1 @@
|
|||
foo=bar
|
||||
Loading…
Reference in New Issue