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 Juergen Hoeller
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Dave Syer
|
||||||
* @since 2.5.2
|
* @since 2.5.2
|
||||||
*/
|
*/
|
||||||
abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
|
||||||
|
|
@ -44,10 +45,28 @@ abstract class AbstractPropertyLoadingBeanDefinitionParser extends AbstractSingl
|
||||||
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
|
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
|
||||||
builder.addPropertyValue("locations", locations);
|
builder.addPropertyValue("locations", locations);
|
||||||
}
|
}
|
||||||
|
|
||||||
String propertiesRef = element.getAttribute("properties-ref");
|
String propertiesRef = element.getAttribute("properties-ref");
|
||||||
if (StringUtils.hasLength(propertiesRef)) {
|
if (StringUtils.hasLength(propertiesRef)) {
|
||||||
builder.addPropertyReference("properties", 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);
|
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,11 +19,13 @@ package org.springframework.context.config;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
|
import org.springframework.beans.factory.config.PropertyOverrideConfigurer;
|
||||||
|
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser for the <context:property-override/> element.
|
* Parser for the <context:property-override/> element.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Dave Syer
|
||||||
* @since 2.5.2
|
* @since 2.5.2
|
||||||
*/
|
*/
|
||||||
class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
||||||
|
|
@ -33,4 +35,13 @@ class PropertyOverrideBeanDefinitionParser extends AbstractPropertyLoadingBeanDe
|
||||||
return PropertyOverrideConfigurer.class;
|
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.w3c.dom.Element;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
|
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.
|
* Parser for the <context:property-placeholder/> element.
|
||||||
*
|
*
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
|
* @author Dave Syer
|
||||||
* @since 2.5
|
* @since 2.5
|
||||||
*/
|
*/
|
||||||
class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser {
|
||||||
|
|
@ -33,4 +36,19 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBea
|
||||||
return PropertyPlaceholderConfigurer.class;
|
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"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<xsd:schema xmlns="http://www.springframework.org/schema/context" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
<xsd:schema xmlns="http://www.springframework.org/schema/context"
|
||||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||||
xmlns:tool="http://www.springframework.org/schema/tool"
|
xmlns:tool="http://www.springframework.org/schema/tool"
|
||||||
targetNamespace="http://www.springframework.org/schema/context" elementFormDefault="qualified"
|
targetNamespace="http://www.springframework.org/schema/context"
|
||||||
attributeFormDefault="unqualified">
|
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/beans"
|
||||||
<xsd:import namespace="http://www.springframework.org/schema/tool" schemaLocation="http://www.springframework.org/schema/tool/spring-tool-3.0.xsd"/>
|
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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
|
|
@ -17,20 +19,7 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
||||||
<xsd:element name="property-placeholder">
|
<xsd:complexType name="propertyPlaceholder">
|
||||||
<xsd:annotation>
|
|
||||||
<xsd:documentation><![CDATA[
|
|
||||||
Activates replacement of ${...} placeholders, resolved against the specified properties file or
|
|
||||||
Properties object (if any). Falls back to resolving placeholders against JVM system properties.
|
|
||||||
Alternatively, define a parameterized PropertyPlaceholderConfigurer bean in the context.
|
|
||||||
]]></xsd:documentation>
|
|
||||||
<xsd:appinfo>
|
|
||||||
<tool:annotation>
|
|
||||||
<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:attribute name="location" type="xsd:string">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
|
|
@ -49,6 +38,84 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</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[
|
||||||
|
Activates replacement of ${...} placeholders, resolved against the specified properties file or
|
||||||
|
Properties object (if any). Falls back to resolving placeholders against JVM system properties.
|
||||||
|
Alternatively, define a parameterized PropertyPlaceholderConfigurer bean in the context.
|
||||||
|
]]></xsd:documentation>
|
||||||
|
<xsd:appinfo>
|
||||||
|
<tool:annotation>
|
||||||
|
<tool:exports
|
||||||
|
type="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />
|
||||||
|
</tool:annotation>
|
||||||
|
</xsd:appinfo>
|
||||||
|
</xsd:annotation>
|
||||||
|
<xsd:complexType>
|
||||||
|
<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:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
|
|
||||||
|
|
@ -60,27 +127,15 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:exports type="org.springframework.beans.factory.config.PropertyOverrideConfigurer"/>
|
<tool:exports
|
||||||
|
type="org.springframework.beans.factory.config.PropertyOverrideConfigurer" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
<xsd:complexType>
|
<xsd:complexType>
|
||||||
<xsd:attribute name="location" type="xsd:string">
|
<xsd:complexContent>
|
||||||
<xsd:annotation>
|
<xsd:extension base="propertyPlaceholder" />
|
||||||
<xsd:documentation><![CDATA[
|
</xsd:complexContent>
|
||||||
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:complexType>
|
</xsd:complexType>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
|
|
||||||
|
|
@ -123,14 +178,16 @@
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
<xsd:complexType>
|
<xsd:complexType>
|
||||||
<xsd:sequence>
|
<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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Controls which eligible types to include for component scanning.
|
Controls which eligible types to include for component scanning.
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:element>
|
</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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Controls which eligible types to exclude for component scanning.
|
Controls which eligible types to exclude for component scanning.
|
||||||
|
|
@ -138,7 +195,8 @@
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:element>
|
</xsd:element>
|
||||||
</xsd:sequence>
|
</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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
The comma-separated list of packages to scan for annotated components.
|
The comma-separated list of packages to scan for annotated components.
|
||||||
|
|
@ -152,7 +210,8 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service,
|
Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service,
|
||||||
|
|
@ -160,7 +219,8 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
</xsd:attribute>
|
</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:annotation>
|
||||||
<xsd:documentation><![CDATA[
|
<xsd:documentation><![CDATA[
|
||||||
Indicates whether the implicit annotation post-processors should be enabled. Default is "true".
|
Indicates whether the implicit annotation post-processors should be enabled. Default is "true".
|
||||||
|
|
@ -175,7 +235,8 @@
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:expected-type type="java.lang.Class" />
|
<tool:expected-type type="java.lang.Class" />
|
||||||
<tool:assignable-to type="org.springframework.beans.factory.support.BeanNameGenerator"/>
|
<tool:assignable-to
|
||||||
|
type="org.springframework.beans.factory.support.BeanNameGenerator" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
@ -189,7 +250,8 @@
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:expected-type type="java.lang.Class" />
|
<tool:expected-type type="java.lang.Class" />
|
||||||
<tool:assignable-to type="org.springframework.context.annotation.ScopeMetadataResolver"/>
|
<tool:assignable-to
|
||||||
|
type="org.springframework.context.annotation.ScopeMetadataResolver" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
@ -238,7 +300,8 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:exports type="org.springframework.instrument.classloading.LoadTimeWeaver"/>
|
<tool:exports
|
||||||
|
type="org.springframework.instrument.classloading.LoadTimeWeaver" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
@ -251,7 +314,8 @@
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:expected-type type="java.lang.Class" />
|
<tool:expected-type type="java.lang.Class" />
|
||||||
<tool:assignable-to type="org.springframework.instrument.classloading.LoadTimeWeaver"/>
|
<tool:assignable-to
|
||||||
|
type="org.springframework.instrument.classloading.LoadTimeWeaver" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
@ -290,7 +354,8 @@
|
||||||
|
|
||||||
<xsd:element name="spring-configured">
|
<xsd:element name="spring-configured">
|
||||||
<xsd:annotation>
|
<xsd:annotation>
|
||||||
<xsd:documentation source="java:org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
|
<xsd:documentation
|
||||||
|
source="java:org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect">
|
||||||
<![CDATA[
|
<![CDATA[
|
||||||
Signals the current application context to apply dependency injection
|
Signals the current application context to apply dependency injection
|
||||||
to non-managed classes that are instantiated outside of the Spring bean
|
to non-managed classes that are instantiated outside of the Spring bean
|
||||||
|
|
@ -304,7 +369,8 @@
|
||||||
|
|
||||||
<xsd:element name="mbean-export">
|
<xsd:element name="mbean-export">
|
||||||
<xsd:annotation>
|
<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
|
Activates default exporting of MBeans by detecting standard MBeans in the Spring
|
||||||
context as well as @ManagedResource annotations on Spring-defined beans.
|
context as well as @ManagedResource annotations on Spring-defined beans.
|
||||||
|
|
||||||
|
|
@ -313,7 +379,8 @@
|
||||||
]]></xsd:documentation>
|
]]></xsd:documentation>
|
||||||
<xsd:appinfo>
|
<xsd:appinfo>
|
||||||
<tool:annotation>
|
<tool:annotation>
|
||||||
<tool:exports type="org.springframework.jmx.export.annotation.AnnotationMBeanExporter"/>
|
<tool:exports
|
||||||
|
type="org.springframework.jmx.export.annotation.AnnotationMBeanExporter" />
|
||||||
</tool:annotation>
|
</tool:annotation>
|
||||||
</xsd:appinfo>
|
</xsd:appinfo>
|
||||||
</xsd:annotation>
|
</xsd:annotation>
|
||||||
|
|
@ -357,7 +424,8 @@
|
||||||
|
|
||||||
<xsd:element name="mbean-server">
|
<xsd:element name="mbean-server">
|
||||||
<xsd:annotation>
|
<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.
|
Exposes a default MBeanServer for the current platform.
|
||||||
Autodetects WebLogic 9+, WebSphere 6.1+ and the JDK 1.5+ platform MBeanServer.
|
Autodetects WebLogic 9+, WebSphere 6.1+ and the JDK 1.5+ platform MBeanServer.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package org.springframework.context.config;
|
package org.springframework.context.config;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
@ -31,30 +32,76 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
|
* @author Dave Syer
|
||||||
* @since 2.5.6
|
* @since 2.5.6
|
||||||
*/
|
*/
|
||||||
public class ContextNamespaceHandlerTests {
|
public class ContextNamespaceHandlerTests {
|
||||||
|
|
||||||
private ApplicationContext applicationContext;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void createAppContext() {
|
|
||||||
applicationContext = new ClassPathXmlApplicationContext("contextNamespaceHandlerTests.xml", getClass());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertyPlaceholder() throws Exception {
|
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());
|
assertFalse("No PropertyPlaceHolderConfigurer found", beans.isEmpty());
|
||||||
String s = (String) applicationContext.getBean("string");
|
String s = (String) applicationContext.getBean("string");
|
||||||
assertEquals("No properties replaced", "bar", s);
|
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
|
@Test
|
||||||
public void propertyOverride() throws Exception {
|
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());
|
assertFalse("No PropertyOverrideConfigurer found", beans.isEmpty());
|
||||||
Date date = (Date) applicationContext.getBean("date");
|
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"
|
<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: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
|
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">
|
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
|
||||||
|
|
||||||
<util:properties id="placeholderProps">
|
<util:properties id="placeholderProps">
|
||||||
<prop key="foo">bar</prop>
|
<prop key="foo">bar</prop>
|
||||||
</util:properties>
|
</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">
|
<bean id="string" class="java.lang.String">
|
||||||
<constructor-arg value="${foo}"/>
|
<constructor-arg value="${foo}"/>
|
||||||
</bean>
|
</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>
|
</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