简体   繁体   English

使用Spark-java和Tomcat提供静态文件

[英]Serving static files using Spark-java and Tomcat

Previously I was using Jetty as a web-server for my Spark application. 以前,我将Jetty用作Spark应用程序的Web服务器。 Now I want to deploy my app to Tomcat and everything is working fine except static files serving. 现在,我想将我的应用程序部署到Tomcat,并且除静态文件服务外,其他所有功能都可以正常工作。 The way I'm trying to setup static files serving is as follows 我尝试设置静态文件投放的方式如下

public class MySparkApplication implements SparkApplication {
    public void init() {
        staticFiles.location("/public");
        spark.Spark.get("/", (req, res) -> "test is OK");
    }
}

And my WAR-archive folder structure is 我的WAR归档文件夹结构是

/META-INF
/WEB-INF
   /classes
   /lib
   /public
       test.html

But it doesn't work and I'm getting 404 when I'm trying to get test.html. 但是它不起作用,当我尝试获取test.html时得到404。 What am I doing wrong? 我究竟做错了什么?

/public should not be in WEB-INF. / public不应位于WEB-INF中。 It should be in the directory, which also contains WEB-INF (The webapps root directory). 它应该在目录中,该目录还包含WEB-INF(webapps根目录)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM