Skip to content

Commit

Permalink
Fix absolute file detection on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mbenson authored and snicoll committed Jun 23, 2015
1 parent 6fd3042 commit 80deaf6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.util.Assert;
import org.springframework.util.ResourceUtils;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindException;

Expand Down Expand Up @@ -455,10 +456,10 @@ private Set<String> getSearchLocations() {
for (String path : asResolvedSet(
this.environment.getProperty(CONFIG_LOCATION_PROPERTY), null)) {
if (!path.contains("$")) {
if (!path.contains(":")) {
path = "file:" + path;
}
path = StringUtils.cleanPath(path);
if (!ResourceUtils.isUrl(path)) {
path = ResourceUtils.FILE_URL_PREFIX + path;
}
}
locations.add(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,16 @@ public void specificResourceDefaultsToFile() throws Exception {
+ 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
public void propertySourceAnnotation() throws Exception {
SpringApplication application = new SpringApplication(WithPropertySource.class);
Expand Down

0 comments on commit 80deaf6

Please sign in to comment.