List of usage examples for org.springframework.web.servlet.function PathResourceLookupFunction PathResourceLookupFunction
public PathResourceLookupFunction(String pattern, Resource location)
From source file:org.springframework.web.servlet.function.RouterFunctions.java
/** * Returns the resource lookup function used by {@link #resources(String, Resource)}. * The returned function can be {@linkplain Function#andThen(Function) composed} on, for * instance to return a default resource when the lookup function does not match: * <pre class="code">//from ww w . jav a2s . c om * Mono<Resource> defaultResource = Mono.just(new ClassPathResource("index.html")); * Function<ServerRequest, Mono<Resource>> lookupFunction = * RouterFunctions.resourceLookupFunction("/resources/**", new FileSystemResource("public-resources/")) * .andThen(resourceMono -> resourceMono.switchIfEmpty(defaultResource)); * RouterFunction<ServerResponse> resources = RouterFunctions.resources(lookupFunction); * </pre> * @param pattern the pattern to match * @param location the location directory relative to which resources should be resolved * @return the default resource lookup function for the given parameters. */ public static Function<ServerRequest, Optional<Resource>> resourceLookupFunction(String pattern, Resource location) { return new PathResourceLookupFunction(pattern, location); }