diff --git a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java index 8580b723b0..3e2e6cc621 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java @@ -473,15 +473,7 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, msg.append("Skipped "); } msg.append("config file "); - String resourceDescription; - try { - resourceDescription = String.format("'%s' (%s)", - resource.getURI().toASCIIString(), location); - } - catch (IOException ex) { - resourceDescription = String.format("'%s'", location); - } - msg.append(resourceDescription); + msg.append(getResourceDescription(location, resource)); if (StringUtils.hasLength(profile)) { msg.append(" for profile ").append(profile); } @@ -495,6 +487,25 @@ public class ConfigFileApplicationListener implements EnvironmentPostProcessor, return propertySource; } + /** + * @param location + * @param resource + * @return + */ + private String getResourceDescription(String location, Resource resource) { + String resourceDescription = "'" + location + "'"; + if (resource != null) { + try { + resourceDescription = String.format("'%s' (%s)", + resource.getURI().toASCIIString(), location); + } + catch (IOException ex) { + // Use the location as the description + } + } + return resourceDescription; + } + private void handleProfileProperties(PropertySource propertySource) { Set activeProfiles = getProfilesForValue( propertySource.getProperty(ACTIVE_PROFILES_PROPERTY)); diff --git a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java index 5ecc1d6017..04b7369dea 100644 --- a/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java +++ b/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java @@ -467,7 +467,11 @@ public class ConfigFileApplicationListenerTests { private String createLogForProfile(String profile) { String suffix = profile != null ? "-" + profile : ""; - return "Loaded config file 'classpath:/application" + suffix + ".properties'"; + String string = ".properties)"; + return "Loaded config file '" + + new File("target/test-classes/application" + suffix + ".properties") + .getAbsoluteFile().toURI().toString() + + "' (classpath:/application" + suffix + string; } @Test