[英]Spring boot: How to read external files reside in Tomcat when deployed as war
I am deploying a Spring boot application as a war to my existing Tomcat server.我正在将 Spring 启动应用程序作为战争部署到我现有的 Tomcat 服务器。 I will write to a json file which resides in
/conf/my.json
in the root of my Tomcat server.我将写入一个 json 文件,该文件位于 Tomcat 服务器根目录的
/conf/my.json
中。
My Spring boot will be deployed in webapp
in the root of my Tomcat server so, say my Spring boot app called mySpring
, it will be at location /webapp/mySpring
.我的 Spring Boot 将部署在我的 Tomcat 服务器根目录中的
webapp
中,因此,假设我的 Spring Boot 应用程序名为mySpring
,它将位于/webapp/mySpring
位置。
How can I read the my.json
in my Spring boot app?如何在 Spring Boot 应用程序中读取
my.json
?
Thanks谢谢
you can use ResourceUtils to get the file.您可以使用 ResourceUtils 来获取文件。 File file= ResourceUtils.getFile( "classpath:conf/my.json");
File file= ResourceUtils.getFile( "classpath:conf/my.json");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.