diff --git a/spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java index cf496b734641..4f994d4b2bbd 100644 --- a/spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/PropertyOverrideBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,8 +37,8 @@ protected Class getBeanClass(Element element) { @Override protected void doParse(Element element, BeanDefinitionBuilder builder) { - super.doParse(element, builder); + builder.addPropertyValue("ignoreInvalidKeys", Boolean.valueOf(element.getAttribute("ignore-unresolvable"))); diff --git a/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java index 60d55605b383..bccffe48c895 100644 --- a/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/PropertyPlaceholderBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,8 +34,10 @@ class PropertyPlaceholderBeanDefinitionParser extends AbstractPropertyLoadingBeanDefinitionParser { private static final String SYSTEM_PROPERTIES_MODE_ATTRIB = "system-properties-mode"; + private static final String SYSTEM_PROPERTIES_MODE_DEFAULT = "ENVIRONMENT"; + @Override protected Class getBeanClass(Element element) { // As of Spring 3.1, the default value of system-properties-mode has changed from @@ -61,7 +63,11 @@ protected void doParse(Element element, BeanDefinitionBuilder builder) { String systemPropertiesModeName = element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIB); if (StringUtils.hasLength(systemPropertiesModeName) && !systemPropertiesModeName.equals(SYSTEM_PROPERTIES_MODE_DEFAULT)) { - builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_"+systemPropertiesModeName); + builder.addPropertyValue("systemPropertiesModeName", "SYSTEM_PROPERTIES_MODE_" + systemPropertiesModeName); + } + + if (element.hasAttribute("null-value")) { + builder.addPropertyValue("nullValue", element.getAttribute("null-value")); } } diff --git a/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.2.xsd b/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.2.xsd index d9aeea34c1ae..016a2f3d832d 100644 --- a/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.2.xsd +++ b/spring-context/src/main/resources/org/springframework/context/config/spring-context-4.2.xsd @@ -19,7 +19,7 @@ ]]> - + - + + + + + + @@ -163,7 +171,7 @@ - + diff --git a/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java b/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java index 0258fa1600b1..91f9e636dc2e 100644 --- a/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/context/config/ContextNamespaceHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,7 @@ public void tearDown() { System.getProperties().remove("foo"); } + @Test public void propertyPlaceholder() throws Exception { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( @@ -55,7 +56,8 @@ public void propertyPlaceholder() throws Exception { .getBeansOfType(PlaceholderConfigurerSupport.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); String s = (String) applicationContext.getBean("string"); - assertEquals("No properties replaced", "bar", s); + assertEquals("bar", s); + assertEquals("null", applicationContext.getBean("nullString")); } @Test @@ -68,8 +70,9 @@ public void propertyPlaceholderSystemProperties() throws Exception { .getBeansOfType(PropertyPlaceholderConfigurer.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); String s = (String) applicationContext.getBean("string"); - assertEquals("No properties replaced", "spam", s); - } finally { + assertEquals("spam", s); + } + finally { if (value!=null) { System.setProperty("foo", value); } @@ -87,7 +90,7 @@ public void propertyPlaceholderEnvironmentProperties() throws Exception { .getBeansOfType(PlaceholderConfigurerSupport.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); String s = (String) applicationContext.getBean("string"); - assertEquals("No properties replaced", "spam", s); + assertEquals("spam", s); } @Test @@ -98,11 +101,11 @@ public void propertyPlaceholderLocation() throws Exception { .getBeansOfType(PropertyPlaceholderConfigurer.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); String s = (String) applicationContext.getBean("foo"); - assertEquals("No properties replaced", "bar", s); + assertEquals("bar", s); s = (String) applicationContext.getBean("bar"); - assertEquals("No properties replaced", "foo", s); + assertEquals("foo", s); s = (String) applicationContext.getBean("spam"); - assertEquals("No properties replaced", "maps", s); + assertEquals("maps", s); } @Test @@ -113,7 +116,8 @@ public void propertyPlaceholderIgnored() throws Exception { .getBeansOfType(PlaceholderConfigurerSupport.class); assertFalse("No PropertyPlaceholderConfigurer found", beans.isEmpty()); String s = (String) applicationContext.getBean("string"); - assertEquals("Properties replaced", "${bar}", s); + assertEquals("${bar}", s); + assertEquals("null", applicationContext.getBean("nullString")); } @Test @@ -126,6 +130,7 @@ public void propertyOverride() throws Exception { Date date = (Date) applicationContext.getBean("date"); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); - assertEquals("No properties overriden", 42, calendar.get(Calendar.MINUTE)); + assertEquals(42, calendar.get(Calendar.MINUTE)); } + } diff --git a/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace-ignore.xml b/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace-ignore.xml index 4714c36217a8..ea4baaf6006a 100644 --- a/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace-ignore.xml +++ b/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace-ignore.xml @@ -1,18 +1,24 @@ + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> bar + - + + + + + diff --git a/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace.xml b/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace.xml index 92161968f76f..d1a15facf585 100644 --- a/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace.xml +++ b/spring-context/src/test/resources/org/springframework/context/config/contextNamespaceHandlerTests-replace.xml @@ -1,17 +1,19 @@ + xmlns:util="http://www.springframework.org/schema/util" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd + http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.2.xsd"> bar + MYNULL - + @@ -21,4 +23,8 @@ + + + +