简体   繁体   中英

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

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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