如何使用Spring Boot从另一个文件夹加载静态资源

时间:2019-04-27 15:38:01

标签: spring-boot gradle spring-web

我具有以下结构

validate

我正在尝试将index.js呈现为静态资源。我在应用程序中尝试了以下内容...

validateOpt

但是,这并不像我期望的那样托管文件。

如何使用Spring Boot将相对文件作为静态资源托管?

1 个答案:

答案 0 :(得分:0)

这对我有用...

String currentPath = new File(".").getAbsolutePath();
registry.addResourceHandler("/ui/**")
        .addResourceLocations("file:///"+currentPath+"/../ui/dist/");