Skip to content

Commit 662d8aa

Browse files
committed
util:properties supports multiple resource locations and ignore-resource-not-found
Issue: SPR-10614
1 parent e48c315 commit 662d8aa

File tree

4 files changed

+106
-50
lines changed

4 files changed

+106
-50
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/xml/UtilNamespaceHandler.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -120,12 +120,14 @@ protected Class<?> getBeanClass(Element element) {
120120

121121
@Override
122122
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
123-
String listClass = element.getAttribute("list-class");
124123
List<Object> parsedList = parserContext.getDelegate().parseListElement(element, builder.getRawBeanDefinition());
125124
builder.addPropertyValue("sourceList", parsedList);
125+
126+
String listClass = element.getAttribute("list-class");
126127
if (StringUtils.hasText(listClass)) {
127128
builder.addPropertyValue("targetListClass", listClass);
128129
}
130+
129131
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
130132
if (StringUtils.hasLength(scope)) {
131133
builder.setScope(scope);
@@ -143,12 +145,14 @@ protected Class<?> getBeanClass(Element element) {
143145

144146
@Override
145147
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
146-
String setClass = element.getAttribute("set-class");
147148
Set<Object> parsedSet = parserContext.getDelegate().parseSetElement(element, builder.getRawBeanDefinition());
148149
builder.addPropertyValue("sourceSet", parsedSet);
150+
151+
String setClass = element.getAttribute("set-class");
149152
if (StringUtils.hasText(setClass)) {
150153
builder.addPropertyValue("targetSetClass", setClass);
151154
}
155+
152156
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
153157
if (StringUtils.hasLength(scope)) {
154158
builder.setScope(scope);
@@ -166,12 +170,14 @@ protected Class<?> getBeanClass(Element element) {
166170

167171
@Override
168172
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
169-
String mapClass = element.getAttribute("map-class");
170173
Map<Object, Object> parsedMap = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
171174
builder.addPropertyValue("sourceMap", parsedMap);
175+
176+
String mapClass = element.getAttribute("map-class");
172177
if (StringUtils.hasText(mapClass)) {
173178
builder.addPropertyValue("targetMapClass", mapClass);
174179
}
180+
175181
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
176182
if (StringUtils.hasLength(scope)) {
177183
builder.setScope(scope);
@@ -180,23 +186,30 @@ protected void doParse(Element element, ParserContext parserContext, BeanDefinit
180186
}
181187

182188

183-
private static class PropertiesBeanDefinitionParser extends AbstractSimpleBeanDefinitionParser {
189+
private static class PropertiesBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
184190

185191
@Override
186192
protected Class<?> getBeanClass(Element element) {
187193
return PropertiesFactoryBean.class;
188194
}
189195

190-
@Override
191-
protected boolean isEligibleAttribute(String attributeName) {
192-
return super.isEligibleAttribute(attributeName) && !SCOPE_ATTRIBUTE.equals(attributeName);
193-
}
194-
195196
@Override
196197
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
197-
super.doParse(element, parserContext, builder);
198198
Properties parsedProps = parserContext.getDelegate().parsePropsElement(element);
199199
builder.addPropertyValue("properties", parsedProps);
200+
201+
String location = element.getAttribute("location");
202+
if (StringUtils.hasLength(location)) {
203+
String[] locations = StringUtils.commaDelimitedListToStringArray(location);
204+
builder.addPropertyValue("locations", locations);
205+
}
206+
207+
builder.addPropertyValue("ignoreResourceNotFound",
208+
Boolean.valueOf(element.getAttribute("ignore-resource-not-found")));
209+
210+
builder.addPropertyValue("localOverride",
211+
Boolean.valueOf(element.getAttribute("local-override")));
212+
200213
String scope = element.getAttribute(SCOPE_ATTRIBUTE);
201214
if (StringUtils.hasLength(scope)) {
202215
builder.setScope(scope);

spring-beans/src/main/resources/org/springframework/beans/factory/xml/spring-util-4.1.xsd

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,23 @@
177177
<xsd:attribute name="id" type="xsd:string"/>
178178
<xsd:attribute name="location" type="xsd:string">
179179
<xsd:annotation>
180-
<xsd:appinfo>
181-
<tool:annotation>
182-
<tool:expected-type type="org.springframework.core.io.Resource"/>
183-
</tool:annotation>
184-
</xsd:appinfo>
180+
<xsd:documentation><![CDATA[
181+
The location of the properties file, as a Spring resource location: a URL,
182+
a "classpath:" pseudo URL, or a relative file path. Multiple locations may be
183+
specified, separated by commas.
184+
]]></xsd:documentation>
185+
</xsd:annotation>
186+
</xsd:attribute>
187+
<xsd:attribute name="ignore-resource-not-found" type="xsd:boolean" default="false">
188+
<xsd:annotation>
189+
<xsd:documentation><![CDATA[
190+
Specifies if failure to find the property resource location should be ignored.
191+
Default is "false", meaning that if there is no file in the location specified
192+
an exception will be raised at runtime.
193+
]]></xsd:documentation>
185194
</xsd:annotation>
186195
</xsd:attribute>
187-
<xsd:attribute name="local-override" type="xsd:boolean">
196+
<xsd:attribute name="local-override" type="xsd:boolean" default="false">
188197
<xsd:annotation>
189198
<xsd:documentation><![CDATA[
190199
Specifies whether local properties override properties from files.

0 commit comments

Comments
 (0)