mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Fix absolute file detection on Windows
Closes gh-3299
This commit is contained in:
parent
6fd3042462
commit
80deaf6456
@ -54,6 +54,7 @@ import org.springframework.core.io.DefaultResourceLoader;
|
|||||||
import org.springframework.core.io.Resource;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
import org.springframework.util.ResourceUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
|
|
||||||
@ -455,10 +456,10 @@ public class ConfigFileApplicationListener implements
|
|||||||
for (String path : asResolvedSet(
|
for (String path : asResolvedSet(
|
||||||
this.environment.getProperty(CONFIG_LOCATION_PROPERTY), null)) {
|
this.environment.getProperty(CONFIG_LOCATION_PROPERTY), null)) {
|
||||||
if (!path.contains("$")) {
|
if (!path.contains("$")) {
|
||||||
if (!path.contains(":")) {
|
|
||||||
path = "file:" + path;
|
|
||||||
}
|
|
||||||
path = StringUtils.cleanPath(path);
|
path = StringUtils.cleanPath(path);
|
||||||
|
if (!ResourceUtils.isUrl(path)) {
|
||||||
|
path = ResourceUtils.FILE_URL_PREFIX + path;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
locations.add(path);
|
locations.add(path);
|
||||||
}
|
}
|
||||||
|
@ -458,6 +458,16 @@ public class ConfigFileApplicationListenerTests {
|
|||||||
+ location + "]"));
|
+ location + "]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void absoluteResourceDefaultsToFile() throws Exception {
|
||||||
|
String location = new File("src/test/resources/specificlocation.properties").getAbsolutePath();
|
||||||
|
EnvironmentTestUtils.addEnvironment(this.environment, "spring.config.location:"
|
||||||
|
+ location);
|
||||||
|
this.initializer.onApplicationEvent(this.event);
|
||||||
|
assertThat(this.environment, containsPropertySource("applicationConfig: [file:"
|
||||||
|
+ location.replace(File.separatorChar, '/') + "]"));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void propertySourceAnnotation() throws Exception {
|
public void propertySourceAnnotation() throws Exception {
|
||||||
SpringApplication application = new SpringApplication(WithPropertySource.class);
|
SpringApplication application = new SpringApplication(WithPropertySource.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user