Skip to content

Commit 80deaf6

Browse files
mbensonsnicoll
authored andcommitted
Fix absolute file detection on Windows
Closes gh-3299
1 parent 6fd3042 commit 80deaf6

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

spring-boot/src/main/java/org/springframework/boot/context/config/ConfigFileApplicationListener.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import org.springframework.core.io.Resource;
5555
import org.springframework.core.io.ResourceLoader;
5656
import org.springframework.util.Assert;
57+
import org.springframework.util.ResourceUtils;
5758
import org.springframework.util.StringUtils;
5859
import org.springframework.validation.BindException;
5960

@@ -455,10 +456,10 @@ private Set<String> getSearchLocations() {
455456
for (String path : asResolvedSet(
456457
this.environment.getProperty(CONFIG_LOCATION_PROPERTY), null)) {
457458
if (!path.contains("$")) {
458-
if (!path.contains(":")) {
459-
path = "file:" + path;
460-
}
461459
path = StringUtils.cleanPath(path);
460+
if (!ResourceUtils.isUrl(path)) {
461+
path = ResourceUtils.FILE_URL_PREFIX + path;
462+
}
462463
}
463464
locations.add(path);
464465
}

spring-boot/src/test/java/org/springframework/boot/context/config/ConfigFileApplicationListenerTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ public void specificResourceDefaultsToFile() throws Exception {
458458
+ location + "]"));
459459
}
460460

461+
@Test
462+
public void absoluteResourceDefaultsToFile() throws Exception {
463+
String location = new File("src/test/resources/specificlocation.properties").getAbsolutePath();
464+
EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:"
465+
+ location);
466+
this.initializer.onApplicationEvent(this.event);
467+
assertThat(this.environment, containsPropertySource("applicationConfig: [file:"
468+
+ location.replace(File.separatorChar, '/') + "]"));
469+
}
470+
461471
@Test
462472
public void propertySourceAnnotation() throws Exception {
463473
SpringApplication application = new SpringApplication(WithPropertySource.class);

0 commit comments

Comments
 (0)