|
|
|
@ -17,6 +17,8 @@
|
|
|
|
|
package org.springframework.boot.autoconfigure.web.reactive;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
@ -50,6 +52,7 @@ import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.context.annotation.Import;
|
|
|
|
|
import org.springframework.core.Ordered;
|
|
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
|
|
import org.springframework.core.io.ResourceLoader;
|
|
|
|
|
import org.springframework.format.FormatterRegistry;
|
|
|
|
|
import org.springframework.format.support.FormattingConversionService;
|
|
|
|
|
import org.springframework.http.codec.ServerCodecConfigurer;
|
|
|
|
@ -156,12 +159,14 @@ public class WebFluxAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
private final ObjectProvider<ViewResolver> viewResolvers;
|
|
|
|
|
|
|
|
|
|
private final ResourceLoader resourceLoader;
|
|
|
|
|
|
|
|
|
|
public WebFluxConfig(org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties,
|
|
|
|
|
WebProperties webProperties, WebFluxProperties webFluxProperties, ListableBeanFactory beanFactory,
|
|
|
|
|
ObjectProvider<HandlerMethodArgumentResolver> resolvers,
|
|
|
|
|
ObjectProvider<CodecCustomizer> codecCustomizers,
|
|
|
|
|
ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizer,
|
|
|
|
|
ObjectProvider<ViewResolver> viewResolvers) {
|
|
|
|
|
ObjectProvider<ViewResolver> viewResolvers, ResourceLoader resourceLoader) {
|
|
|
|
|
this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties
|
|
|
|
|
: webProperties.getResources();
|
|
|
|
|
this.webFluxProperties = webFluxProperties;
|
|
|
|
@ -170,6 +175,7 @@ public class WebFluxAutoConfiguration {
|
|
|
|
|
this.codecCustomizers = codecCustomizers;
|
|
|
|
|
this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizer.getIfAvailable();
|
|
|
|
|
this.viewResolvers = viewResolvers;
|
|
|
|
|
this.resourceLoader = resourceLoader;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -189,19 +195,30 @@ public class WebFluxAutoConfiguration {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!registry.hasMappingForPattern("/webjars/**")) {
|
|
|
|
|
String webjarsLocation = "classpath:/META-INF/resources/webjars/";
|
|
|
|
|
if (this.resourceLoader.getResource(webjarsLocation).exists()) {
|
|
|
|
|
ResourceHandlerRegistration registration = registry.addResourceHandler("/webjars/**")
|
|
|
|
|
.addResourceLocations("classpath:/META-INF/resources/webjars/");
|
|
|
|
|
.addResourceLocations(webjarsLocation);
|
|
|
|
|
configureResourceCaching(registration);
|
|
|
|
|
customizeResourceHandlerRegistration(registration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String staticPathPattern = this.webFluxProperties.getStaticPathPattern();
|
|
|
|
|
if (!registry.hasMappingForPattern(staticPathPattern)) {
|
|
|
|
|
List<String> foundLocations = new ArrayList<>();
|
|
|
|
|
for (String staticLocation : this.resourceProperties.getStaticLocations()) {
|
|
|
|
|
if (this.resourceLoader.getResource(staticLocation).exists()) {
|
|
|
|
|
foundLocations.add(staticLocation);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!foundLocations.isEmpty()) {
|
|
|
|
|
ResourceHandlerRegistration registration = registry.addResourceHandler(staticPathPattern)
|
|
|
|
|
.addResourceLocations(this.resourceProperties.getStaticLocations());
|
|
|
|
|
.addResourceLocations(foundLocations.toArray(new String[0]));
|
|
|
|
|
configureResourceCaching(registration);
|
|
|
|
|
customizeResourceHandlerRegistration(registration);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void configureResourceCaching(ResourceHandlerRegistration registration) {
|
|
|
|
|
Duration cachePeriod = this.resourceProperties.getCache().getPeriod();
|
|
|
|
|