简体   繁体   English

Spring boot:部署为war时如何读取驻留在Tomcat中的外部文件

[英]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.

相关问题 如何在Tomcat 8.5中部署的Spring Boot中使用外部配置文件 - How to use external configuration files with Spring boot deployed in Tomcat 8.5 当以传统方式部署时,Spring Boot尝试运行嵌入式Tomcat - Spring Boot tries to run an embedded Tomcat when deployed as traditional war 春季引导战争到外部雄猫 - spring boot war to external tomcat 如何在Spring Boot应用程序中启用HTTPS,该应用程序在Tomcat中作为WAR文件部署? - How to enable HTTPS in a Spring Boot application, deployed as WAR file in Tomcat? spring boot的嵌入式tomcat服务器如何加载外部“war”文件 - How load a external "war" file to the embedded tomcat server of spring boot Spring Boot 战争在外部 tomcat 中出现异常 - Spring Boot war giving exception in external tomcat spring 启动时是否使用外部服务器或嵌入式服务器作为战争部署在外部服务器上? - Does spring boot uses external server, or embedded server when deployed on external server as war? 在tomcat中部署Spring Boot战争时,应将application.yml文件放在哪里? - when deployed Spring Boot war in tomcat where should application.yml file should be placed? Spring boot WAR 部署到 Tomcat 并且缺少静态资源的上下文 - Spring boot WAR deployed to Tomcat and missing context for static resources Tomcat 战争已部署,但 spring 引导应用程序未开始运行 - Tomcat war gets deployed but spring boot app does not start running
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM