Example usage for org.springframework.web.servlet.function PathResourceLookupFunction PathResourceLookupFunction

List of usage examples for org.springframework.web.servlet.function PathResourceLookupFunction PathResourceLookupFunction

Introduction

In this page you can find the example usage for org.springframework.web.servlet.function PathResourceLookupFunction PathResourceLookupFunction.

Prototype

public PathResourceLookupFunction(String pattern, Resource location) 

Source Link

Usage

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&lt;Resource&gt; defaultResource = Mono.just(new ClassPathResource("index.html"));
 * Function&lt;ServerRequest, Mono&lt;Resource&gt;&gt; lookupFunction =
 *   RouterFunctions.resourceLookupFunction("/resources/**", new FileSystemResource("public-resources/"))
 *     .andThen(resourceMono -&gt; resourceMono.switchIfEmpty(defaultResource));
 * RouterFunction&lt;ServerResponse&gt; 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);
}