Consistent logging in ignoreResourceNotFound scenarios

Issue: SPR-15218
This commit is contained in:
Juergen Hoeller
2017-02-10 10:41:10 +01:00
parent b630c9bea7
commit 448ea4cdfe
4 changed files with 23 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2017 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.
@@ -16,6 +16,7 @@
package org.springframework.core.io.support;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
@@ -168,17 +169,17 @@ public abstract class PropertiesLoaderSupport {
protected void loadProperties(Properties props) throws IOException {
if (this.locations != null) {
for (Resource location : this.locations) {
if (logger.isInfoEnabled()) {
logger.info("Loading properties file from " + location);
if (logger.isDebugEnabled()) {
logger.debug("Loading properties file from " + location);
}
try {
PropertiesLoaderUtils.fillProperties(
props, new EncodedResource(location, this.fileEncoding), this.propertiesPersister);
}
catch (IOException ex) {
catch (FileNotFoundException ex) {
if (this.ignoreResourceNotFound) {
if (logger.isWarnEnabled()) {
logger.warn("Could not load properties from " + location + ": " + ex.getMessage());
if (logger.isInfoEnabled()) {
logger.info("Properties resource not found: " + ex.getMessage());
}
}
else {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -127,11 +127,11 @@ public class PropertyPlaceholderHelper {
}
protected String parseStringValue(
String strVal, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
String value, PlaceholderResolver placeholderResolver, Set<String> visitedPlaceholders) {
StringBuilder result = new StringBuilder(strVal);
StringBuilder result = new StringBuilder(value);
int startIndex = strVal.indexOf(this.placeholderPrefix);
int startIndex = value.indexOf(this.placeholderPrefix);
while (startIndex != -1) {
int endIndex = findPlaceholderEndIndex(result, startIndex);
if (endIndex != -1) {
@@ -172,7 +172,7 @@ public class PropertyPlaceholderHelper {
}
else {
throw new IllegalArgumentException("Could not resolve placeholder '" +
placeholder + "'" + " in string value \"" + strVal + "\"");
placeholder + "'" + " in value \"" + value + "\"");
}
visitedPlaceholders.remove(originalPlaceholder);
}