I haven't used Spring Boot for a while and seem to have a problem getting Spring to serve static assets. My project contains multiple modules - one of which is
Код: Выделить всё
webui
Код: Выделить всё
jar
Код: Выделить всё
webapp
Код: Выделить всё
WebConfiguration
Код: Выделить всё
@Configuration
@EnableWebFlux
public class WebConfig implements WebFluxConfigurer
{
@Bean
RouterFunction redirectToIndex()
{
ClassPathResource index = new ClassPathResource("static/index.html");
List extensions = List.of("js", "css", "ico", "png", "jpg", "gif");
RequestPredicate spaPredicate = path("/api/**").or(path("/error"))
.or(pathExtension(extensions::contains))
.negate();
return route().resource(spaPredicate, index).build();
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry)
{
registry.addResourceHandler("*.html")
.addResourceLocations("classpath*:/static")
.setCacheControl(CacheControl.maxAge(Duration.ofHours(1)));
registry.addResourceHandler("/static/**")
.addResourceLocations("classpath*:/static/")
.setCacheControl(CacheControl.maxAge(Duration.ofHours(1)))
.resourceChain(true)
.addResolver(new EncodedResourceResolver())
.addResolver(new PathResourceResolver());
}
}
There is indeed a
Код: Выделить всё
static/index.html
Код: Выделить всё
static/assets/
Код: Выделить всё
static/index.html
Код: Выделить всё
fat jar

Источник: https://stackoverflow.com/questions/781 ... dependency