-
Notifications
You must be signed in to change notification settings - Fork 38.8k
Closed
Description
Holger Stenzhorn opened SPR-14549 and commented
In relation to #19007, when I now put the following code in my webapp...
@Value("#{servletContext.getRealPath('/resources/ontologies')}")
private void setString(String string) {
System.out.println(string);
}
@Value("#{servletContext.getRealPath('/resources/ontologies')}")
private void setFile(File file) {
System.out.println(file);
}
@Value("#{servletContext.getRealPath('/resources/ontologies')}")
private void setPath(Path path) {
System.out.println(path);
}
...then this results in the following output...
/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies
/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies
/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/Users/holger/Developer/ObTiMA/out/artifacts/ObTiMA_Web_exploded/resources/ontologies
...where the first two lines are indeed correct but the last one is not.
Looking at your implementation of PathEditor
, it seems that the code below from my original post needs to be added to make things work correctly:
// Check whether we got an absolute file path without "file:" prefix.
// For backwards compatibility, we'll consider those as straight file path.
if (!ResourceUtils.isUrl(text)) {
Path path = Paths.get(text);
if (path.isAbsolute()) {
setValue(path);
return;
}
}
Affects: 4.3.2
Issue Links:
- Add PathEditor to enable conversion to java.nio.file.Path [SPR-14436] #19007 Add PathEditor to enable conversion to java.nio.file.Path
- Different handling in PathEditor in Servlet Context for existing and non-existing paths [SPR-15256] #19821 Different handling in PathEditor in Servlet Context for existing and non-existing paths
Metadata
Metadata
Assignees
Labels
type: enhancementA general enhancementA general enhancement