How to dynamically add static resources to spring-boot jar application?

痴心易碎 提交于 2019-12-23 01:07:12

问题


I have spring-boot application which creates catalog with html static pages. When I start application by command: mvn spring-boot:run everything works good (folder with static pages is created in /resources/ catalog and client have access to pages) but I want have my app deployed as jar file and here I have my question, how can I achieve my goal? I understand that I can't add dynamically resources to jar but maybe I can create folder with resources next to my jar file and somehow add this folder to public resources so client could have access to html pages.


回答1:


Try prefixing you resource location with file:, for example:

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/external/**")
            .addResourceLocations("file:external/");
}

This path is relative to the directory from which you launched the application. You can also use an absolute path, for example file:/path/to/resources.



来源:https://stackoverflow.com/questions/25871131/how-to-dynamically-add-static-resources-to-spring-boot-jar-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!