Skip to content

Commit 448ea4c

Browse files
committed
Consistent logging in ignoreResourceNotFound scenarios
Issue: SPR-15218
1 parent b630c9b commit 448ea4c

File tree

4 files changed

+23
-30
lines changed

4 files changed

+23
-30
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,15 +417,14 @@ private void processPropertySource(AnnotationAttributes propertySource) throws I
417417
Resource resource = this.resourceLoader.getResource(resolvedLocation);
418418
addPropertySource(factory.createPropertySource(name, new EncodedResource(resource, encoding)));
419419
}
420-
catch (IllegalArgumentException ex) {
421-
// from resolveRequiredPlaceholders
422-
if (!ignoreResourceNotFound) {
423-
throw ex;
420+
catch (IllegalArgumentException | FileNotFoundException ex) {
421+
// Placeholders not resolvable or resource not found when trying to open it
422+
if (ignoreResourceNotFound) {
423+
if (logger.isInfoEnabled()) {
424+
logger.info("Properties location [" + location + "] not resolvable: " + ex.getMessage());
425+
}
424426
}
425-
}
426-
catch (FileNotFoundException ex) {
427-
// from ResourcePropertySource constructor
428-
if (!ignoreResourceNotFound) {
427+
else {
429428
throw ex;
430429
}
431430
}

spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.core.io.support;
1818

19+
import java.io.FileNotFoundException;
1920
import java.io.IOException;
2021
import java.util.Properties;
2122

@@ -168,17 +169,17 @@ protected Properties mergeProperties() throws IOException {
168169
protected void loadProperties(Properties props) throws IOException {
169170
if (this.locations != null) {
170171
for (Resource location : this.locations) {
171-
if (logger.isInfoEnabled()) {
172-
logger.info("Loading properties file from " + location);
172+
if (logger.isDebugEnabled()) {
173+
logger.debug("Loading properties file from " + location);
173174
}
174175
try {
175176
PropertiesLoaderUtils.fillProperties(
176177
props, new EncodedResource(location, this.fileEncoding), this.propertiesPersister);
177178
}
178-
catch (IOException ex) {
179+
catch (FileNotFoundException ex) {
179180
if (this.ignoreResourceNotFound) {
180-
if (logger.isWarnEnabled()) {
181-
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
181+
if (logger.isInfoEnabled()) {
182+
logger.info("Properties resource not found: " + ex.getMessage());
182183
}
183184
}
184185
else {

spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -127,11 +127,11 @@ public String replacePlaceholders(String value, PlaceholderResolver placeholderR
127127
}
128128

129129
protected String parseStringValue(
130-
String strVal, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
130+
String value, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
131131

132-
StringBuilder result = new StringBuilder(strVal);
132+
StringBuilder result = new StringBuilder(value);
133133

134-
int startIndex = strVal.indexOf(this.placeholderPrefix);
134+
int startIndex = value.indexOf(this.placeholderPrefix);
135135
while (startIndex != -1) {
136136
int endIndex = findPlaceholderEndIndex(result, startIndex);
137137
if (endIndex != -1) {
@@ -172,7 +172,7 @@ else if (this.ignoreUnresolvablePlaceholders) {
172172
}
173173
else {
174174
throw new IllegalArgumentException("Could not resolve placeholder '" +
175-
placeholder + "'" + " in string value \"" + strVal + "\"");
175+
placeholder + "'" + " in value \"" + value + "\"");
176176
}
177177
visitedPlaceholders.remove(originalPlaceholder);
178178
}

spring-core/src/test/java/org/springframework/core/env/PropertySourcesPropertyResolverTests.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 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.
@@ -315,7 +315,7 @@ public void resolveNestedPropertyPlaceholders() {
315315
}
316316
catch (IllegalArgumentException ex) {
317317
assertThat(ex.getMessage(), containsString(
318-
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
318+
"Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\""));
319319
}
320320
assertThat(pr.getProperty("p6"), equalTo("v1:v2:def"));
321321
try {
@@ -347,7 +347,7 @@ public void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
347347
}
348348
catch (IllegalArgumentException ex) {
349349
assertThat(ex.getMessage(), containsString(
350-
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
350+
"Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\""));
351351
}
352352

353353
// relax the treatment of unresolvable nested placeholders
@@ -363,15 +363,8 @@ public void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
363363
}
364364
catch (IllegalArgumentException ex) {
365365
assertThat(ex.getMessage(), containsString(
366-
"Could not resolve placeholder 'bogus' in string value \"${p1}:${p2}:${bogus}\""));
366+
"Could not resolve placeholder 'bogus' in value \"${p1}:${p2}:${bogus}\""));
367367
}
368368
}
369369

370-
371-
interface SomeType {
372-
}
373-
374-
static class SpecificType implements SomeType {
375-
}
376-
377370
}

0 commit comments

Comments
 (0)