diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java index a7f9cee508..0d1fb29713 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java @@ -310,9 +310,9 @@ class ConfigurationClassParser { throw new IllegalArgumentException("At least one @PropertySource(value) location is required"); } for (String location : locations) { - Resource resource = this.resourceLoader.getResource( - this.environment.resolveRequiredPlaceholders(location)); try { + Resource resource = this.resourceLoader.getResource( + this.environment.resolveRequiredPlaceholders(location)); if (!StringUtils.hasText(name) || this.propertySources.containsKey(name)) { // We need to ensure unique names when the property source will // ultimately end up in a composite @@ -323,7 +323,14 @@ class ConfigurationClassParser { this.propertySources.add(name, new ResourcePropertySource(name, resource)); } } + catch (IllegalArgumentException ex) { + // from resolveRequiredPlaceholders + if (!ignoreResourceNotFound) { + throw ex; + } + } catch (FileNotFoundException ex) { + // from ResourcePropertySource constructor if (!ignoreResourceNotFound) { throw ex; } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java b/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java index ec5bca2aff..0776c80153 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/PropertySourceAnnotationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2014 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. @@ -18,12 +18,12 @@ package org.springframework.context.annotation; import java.io.FileNotFoundException; import java.util.Iterator; - import javax.inject.Inject; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; @@ -250,6 +250,7 @@ public class PropertySourceAnnotationTests { static class ConfigWithNameAndMultipleResourceLocations { } + @Configuration @PropertySource( value = { @@ -268,6 +269,7 @@ public class PropertySourceAnnotationTests { static class ConfigWithPropertySources { } + @Configuration @PropertySources({ @PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"), @@ -282,13 +284,16 @@ public class PropertySourceAnnotationTests { @PropertySources({ @PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p1.properties"), @PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/missing.properties", ignoreResourceNotFound=true), + @PropertySource(name = "psName", value="classpath:${myPath}/missing.properties", ignoreResourceNotFound=true), @PropertySource(name = "psName", value="classpath:org/springframework/context/annotation/p2.properties") }) static class ConfigWithIgnoredPropertySource { } + @Configuration @PropertySource(value = {}) static class ConfigWithEmptyResourceLocations { } + }