Spring boot webflux, обслуживающий статические ресурсы из зависимостиJAVA

Программисты JAVA общаются здесь
Гость
Spring boot webflux, обслуживающий статические ресурсы из зависимости

Сообщение Гость »


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 . It builds an Angular application and archives it into a . This dependency is then consumed from the and is included in the fat jar. I have the following

Код: Выделить всё

WebConfiguration
class:

Код: Выделить всё

@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());
}

}
Unfortunately this does not seem to be working and I'm sure I'm doing something wrong.
There is indeed a

Код: Выделить всё

static/index.html
and

Код: Выделить всё

static/assets/
resource, but that's under a 3rd party dependency. I have a feeling that

Код: Выделить всё

static/index.html
refers to the top root of the . What am I doing wrong?
Изображение



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

Вернуться в «JAVA»