Spring ResourceLoader正在引发异常
我有如下代码Spring ResourceLoader正在引发异常,spring,file,Spring,File,我有如下代码 public LocalFileStorage(String storageUrl, Resource storageDirectory) { this.storageUrl = storageUrl; try { this.storageDirectory = storageDirectory.getFile(); this.storageDirectory.deleteOnExit(); this.storageD
public LocalFileStorage(String storageUrl, Resource storageDirectory) {
this.storageUrl = storageUrl;
try {
this.storageDirectory = storageDirectory.getFile();
this.storageDirectory.deleteOnExit();
this.storageDirectory.createNewFile();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
我把这个班叫做下面的班
private ResourceLoader resourceLoader; // from spring
LocalFileStorage pictureStorage = new LocalFileStorage(Url+ "/resources/", resourceLoader.getResource("/resources/"));
召唤
resourceLoader.getResource("/resources/")
抛出异常。我认为ResourceLoader加载目录也是因为目录毕竟也是一个文件
我的结构
通常,只有
/WEB-INF/classes
、/WEB-INF/lib
、/WEB-INF/…
中的任何内容才会添加到类路径中,并通过类加载器.getResource()
进行访问。您试图访问的文件夹不在WEB-INF
中,因此不会出现在类路径中
假设您使用的是类似于Maven的东西,那么应该将资源文件放在/src/main/resources
下。构建项目时,这些文件将以WEB-INF/classes
结尾