Serve static resources within jar files by Spring boot

最后都变了- 提交于 2019-12-22 08:16:03

问题


I'm developing a solution by multiple maven modules to handle different bounded contexts.

Thanks to spring boot each module exposes own rest api and all of them hosted in one maven module with a class that annotated by @SpringBootApplication. The simplified project structure is looks like this:

parent  
|-- pom.xml  
|-- ...
|-- host   
  |-- Application.java      
  |-- resources
     |-- index.html
|-- driver
  |-- api     
  |-- resources
     |-- register.html
|-- notify
  |-- ...
|-- passenger
  |-- ...

I've tried to use the same pattern when facing with the composite UI: one place that keeps layouts, static resources and in the meantime, the html pages belong to each bounded context that kept in it's maven module.

The problem is as I've found in the spring boot doc there is no way to serves static resources from the other jar files.

Is there any solution to get this functionality or is there any architectural mistake here? or something outside of the spring (e.g. overlay) is the solution?


回答1:


extends WebMvcConfigurerAdapter and override addResourceHandlers

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

refer spring-boot-app-does-not-serve-static-resources-after-packaging-into-jar



来源:https://stackoverflow.com/questions/38154195/serve-static-resources-within-jar-files-by-spring-boot

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