Skip to content

Commit 2503b7e

Browse files
committed
Fix property replacement bug in Log4jWebConfigurer
Previously, if the resolution of a ${...} placeholder resulted in a valid URL for the location of a log4j properties/XML file, the URL would ultimately be malformed by an unnecessary call to to WebUtils#getRealPath. The implementation of Log4jWebConfigurer#initLogging now eagerly attempts SystemPropertyUtils#resolvePlaceholders before checking to see if the location is a valid URL, and bypassing the call to WebUtils#getRealPath if so. Issue: SPR-9417
1 parent f1246a4 commit 2503b7e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

spring-web/src/main/java/org/springframework/web/util/Log4jWebConfigurer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2012 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.
@@ -124,9 +124,9 @@ public static void initLogging(ServletContext servletContext) {
124124
try {
125125
// Return a URL (e.g. "classpath:" or "file:") as-is;
126126
// consider a plain file path as relative to the web application root directory.
127+
location = SystemPropertyUtils.resolvePlaceholders(location);
127128
if (!ResourceUtils.isUrl(location)) {
128129
// Resolve system property placeholders before resolving real path.
129-
location = SystemPropertyUtils.resolvePlaceholders(location);
130130
location = WebUtils.getRealPath(servletContext, location);
131131
}
132132

spring-web/src/test/java/org/springframework/web/util/Log4jWebConfigurerTests.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 the original author or authors.
2+
* Copyright 2002-2012 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.
@@ -37,8 +37,9 @@
3737
public class Log4jWebConfigurerTests {
3838

3939
private static final String TESTLOG4J_PROPERTIES = "testlog4j.properties";
40-
private static final String CLASSPATH_RESOURCE = "classpath:org/springframework/web/util/testlog4j.properties";
41-
private static final String RELATIVE_PATH = "src/test/resources/org/springframework/web/util/testlog4j.properties";
40+
private static final String PROPERTIES_LOCATION = "org/springframework/web/util/testlog4j.properties";
41+
private static final String CLASSPATH_RESOURCE = "classpath:" + PROPERTIES_LOCATION;
42+
private static final String RELATIVE_PATH = "src/test/resources/" + PROPERTIES_LOCATION;
4243

4344
@Test
4445
public void initLoggingWithClasspathResource() {
@@ -59,7 +60,12 @@ public void initLoggingWithRelativeFilePath() {
5960
public void initLoggingWithRelativeFilePathAndRefreshInterval() {
6061
initLogging(RELATIVE_PATH, true);
6162
}
62-
63+
64+
@Test // See SPR-9417
65+
public void initLoggingWithPlaceholderResolvingToValidUrl() {
66+
initLogging("${some.prop.name:classpath:}" + PROPERTIES_LOCATION, true);
67+
}
68+
6369
@Test
6470
public void initLoggingWithUrl() {
6571
URL url = Log4jWebConfigurerTests.class.getResource(TESTLOG4J_PROPERTIES);

0 commit comments

Comments
 (0)