Where to put static files for Spark Web Framework?

前端 未结 4 904
予麋鹿
予麋鹿 2020-12-08 07:21

Where do I put files when trying to serve static files with the Spark web framework?

I haven\'t been able to find anything online - I\'m beginning to suspect I don\'

4条回答
  •  清歌不尽
    2020-12-08 08:10

    First you have to tell Spark where to search for the static files like this:

    Spark.staticFiles.location("/public");
    

    In Spark versions prior to 2.5, you should use:

    Spark.staticFileLocation("/public");
    

    Then your project should have a public folder under the resources folder like this

    /src/main/resources/public/style.css

    For example I added a style.css file there, so you should then access it like this:

    http://localhost:4567/style.css


    If you want to serve a non-classpath folder, then you should use

    Spark.staticFiles.externalLocation("/path/to/dir");
    

    In Spark versions prior to 2.5, you should use:

    Spark.externalStaticFileLocation("/path/to/dir");
    

提交回复
热议问题