问题
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