我想使用在tomcat9
上运行的Springboot Servlet在此路径中编写文件/mnt/data-new/data/USERPROFILE/607/file.txt
当我尝试编写该文件时,我会收到此错误:
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Jul 03 14:11:39 UTC 2019
There was an unexpected error (type=Internal Server Error, status=500).
/mnt/data-new/data/USERPROFILE/607/file.txt (Read-only file system)
我已经用777在该路径上设置了权限,但没有任何改变。
servlet代码非常简单:
@GetMapping("/")
public String index() throws IOException {
FileWriter fw = new FileWriter("/mnt/data-new/data/USERPROFILE/607/file.txt");
fw.write("File wrote");
fw.close();
return "OK";
}
我创建了一个命名为" file2.txt"的文件,我可以使用此示例代码阅读:
@ResponseBody
@GetMapping("/read")
public String read() throws IOException {
BufferedReader br = new BufferedReader(new FileReader("/mnt/data-new/data/USERPROFILE/607/file2.txt"));
String st;
while ((st = br.readLine()) != null) return st;
return null;
}
我认为这是一项Catalina政策,但似乎是禁用的:
root@devel-spring:/etc/tomcat9# echo $CATALINA_OPTS
-Djava.security.debug=all
,即使有了此选项,我也没有安全管理器登录"/var/log/syslog"
我该怎么做才能在那个绝对路径中编写文件?
编辑:文件系统安装了RW,我可以使用bash创建该文件。
感谢emmanuel bourg在debian bugs.debian.org链接我发现tomcat9
"沙箱只写入自己的目录。 调整SystemD配置以允许Tomcat写入..." [那个]" ...目录"。
所以我是nano'ed/etc/systemd/system/multi-user.target.wants/tomcat9.service添加
ReadWritePaths=/mnt/data-new/data/
然后
systemctl daemon-reload
service tomcat9 restart
现在,
使用上面的代码,我成功地编写了测试文件。