Browse Source

Polishing

pull/1783/head
Juergen Hoeller 8 years ago
parent
commit
2cd006923c
  1. 23
      spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
  2. 82
      spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java

23
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

@ -79,19 +79,17 @@ import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* Spring's default implementation of the * Spring's default implementation of the {@link ConfigurableListableBeanFactory}
* {@link org.springframework.beans.factory.ListableBeanFactory} and * and {@link BeanDefinitionRegistry} interfaces: a full-fledged bean factory
* {@link BeanDefinitionRegistry} interfaces: a full-fledged bean factory * based on bean definition metadata, extensible through post-processors.
* based on bean definition objects.
* *
* <p>Typical usage is registering all bean definitions first (possibly read * <p>Typical usage is registering all bean definitions first (possibly read
* from a bean definition file), before accessing beans. Bean definition lookup * from a bean definition file), before accessing beans. Bean lookup by name
* is therefore an inexpensive operation in a local bean definition table, * is therefore an inexpensive operation in a local bean definition table,
* operating on pre-built bean definition metadata objects. * operating on pre-resolved bean definition metadata objects.
* *
* <p>Can be used as a standalone bean factory, or as a superclass for custom * <p>Note that readers for specific bean definition formats are typically
* bean factories. Note that readers for specific bean definition formats are * implemented separately rather than as bean factory subclasses:
* typically implemented separately rather than as bean factory subclasses:
* see for example {@link PropertiesBeanDefinitionReader} and * see for example {@link PropertiesBeanDefinitionReader} and
* {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}. * {@link org.springframework.beans.factory.xml.XmlBeanDefinitionReader}.
* *
@ -108,9 +106,10 @@ import org.springframework.util.StringUtils;
* @author Phillip Webb * @author Phillip Webb
* @author Stephane Nicoll * @author Stephane Nicoll
* @since 16 April 2001 * @since 16 April 2001
* @see StaticListableBeanFactory * @see #registerBeanDefinition
* @see PropertiesBeanDefinitionReader * @see #addBeanPostProcessor
* @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader * @see #getBean
* @see #resolveDependency
*/ */
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory

82
spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RouterFunctions.java

@ -41,9 +41,8 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
/** /**
* <strong>Central entry point to Spring's functional web framework.</strong> * <strong>Central entry point to Spring's functional web framework.</strong>
* Exposes routing functionality, such as to * Exposes routing functionality, such as to {@linkplain #route() create} a
* {@linkplain #route() create} a {@code RouterFunction} using a discoverable builder-style API, * {@code RouterFunction} using a discoverable builder-style API, to
* to
* {@linkplain #route(RequestPredicate, HandlerFunction) create} a {@code RouterFunction} * {@linkplain #route(RequestPredicate, HandlerFunction) create} a {@code RouterFunction}
* given a {@code RequestPredicate} and {@code HandlerFunction}, and to do further * given a {@code RequestPredicate} and {@code HandlerFunction}, and to do further
* {@linkplain #nest(RequestPredicate, RouterFunction) subrouting} on an existing routing * {@linkplain #nest(RequestPredicate, RouterFunction) subrouting} on an existing routing
@ -72,7 +71,9 @@ public abstract class RouterFunctions {
public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE = public static final String URI_TEMPLATE_VARIABLES_ATTRIBUTE =
RouterFunctions.class.getName() + ".uriTemplateVariables"; RouterFunctions.class.getName() + ".uriTemplateVariables";
private static final HandlerFunction<ServerResponse> NOT_FOUND_HANDLER = request -> ServerResponse.notFound().build(); private static final HandlerFunction<ServerResponse> NOT_FOUND_HANDLER =
request -> ServerResponse.notFound().build();
/** /**
* Offers a discoverable way to create router functions through a builder-style interface. * Offers a discoverable way to create router functions through a builder-style interface.
@ -116,9 +117,8 @@ public abstract class RouterFunctions {
* RouterFunction&lt;ServerResponse&gt; userRoutes = * RouterFunction&lt;ServerResponse&gt; userRoutes =
* RouterFunctions.route(RequestPredicates.method(HttpMethod.GET), this::listUsers) * RouterFunctions.route(RequestPredicates.method(HttpMethod.GET), this::listUsers)
* .andRoute(RequestPredicates.method(HttpMethod.POST), this::createUser); * .andRoute(RequestPredicates.method(HttpMethod.POST), this::createUser);
*
* RouterFunction&lt;ServerResponse&gt; nestedRoute = * RouterFunction&lt;ServerResponse&gt; nestedRoute =
* RouterFunctions.nest(RequestPredicates.path("/user"),userRoutes); * RouterFunctions.nest(RequestPredicates.path("/user"), userRoutes);
* </pre> * </pre>
* @param predicate the predicate to test * @param predicate the predicate to test
* @param routerFunction the nested router function to delegate to if the predicate applies * @param routerFunction the nested router function to delegate to if the predicate applies
@ -158,7 +158,6 @@ public abstract class RouterFunctions {
* Function&lt;ServerRequest, Mono&lt;Resource&gt;&gt; lookupFunction = * Function&lt;ServerRequest, Mono&lt;Resource&gt;&gt; lookupFunction =
* RouterFunctions.resourceLookupFunction("/resources/**", new FileSystemResource("public-resources/")) * RouterFunctions.resourceLookupFunction("/resources/**", new FileSystemResource("public-resources/"))
* .andThen(resourceMono -&gt; resourceMono.switchIfEmpty(defaultResource)); * .andThen(resourceMono -&gt; resourceMono.switchIfEmpty(defaultResource));
*
* RouterFunction&lt;ServerResponse&gt; resources = RouterFunctions.resources(lookupFunction); * RouterFunction&lt;ServerResponse&gt; resources = RouterFunctions.resources(lookupFunction);
* </pre> * </pre>
* @param pattern the pattern to match * @param pattern the pattern to match
@ -259,6 +258,7 @@ public abstract class RouterFunctions {
}; };
} }
private static <T> Mono<T> wrapException(Supplier<Mono<T>> supplier) { private static <T> Mono<T> wrapException(Supplier<Mono<T>> supplier) {
try { try {
return supplier.get(); return supplier.get();
@ -283,9 +283,10 @@ public abstract class RouterFunctions {
return (HandlerFunction<T>) handlerFunction; return (HandlerFunction<T>) handlerFunction;
} }
/** /**
* Represents a discoverable builder for router functions. Obtained via * Represents a discoverable builder for router functions.
* {@link RouterFunctions#route()}. * Obtained via {@link RouterFunctions#route()}.
* @since 5.1 * @since 5.1
*/ */
public interface Builder { public interface Builder {
@ -307,9 +308,8 @@ public abstract class RouterFunctions {
* to the {@code listUsers} method in {@code userController}: * to the {@code listUsers} method in {@code userController}:
* <pre class="code"> * <pre class="code">
* RouterFunction&lt;ServerResponse&gt; route = * RouterFunction&lt;ServerResponse&gt; route =
* RouterFunctions.route() * RouterFunctions.route()
* .GET("/user", RequestPredicates.accept(MediaType.APPLICATION_JSON), * .GET("/user", RequestPredicates.accept(MediaType.APPLICATION_JSON), userController::listUsers)
* userController::listUsers)
* .build(); * .build();
* </pre> * </pre>
* @param pattern the pattern to match to * @param pattern the pattern to match to
@ -359,9 +359,8 @@ public abstract class RouterFunctions {
* to the {@code addUser} method in {@code userController}: * to the {@code addUser} method in {@code userController}:
* <pre class="code"> * <pre class="code">
* RouterFunction&lt;ServerResponse&gt; route = * RouterFunction&lt;ServerResponse&gt; route =
* RouterFunctions.route() * RouterFunctions.route()
* .POST("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), * .POST("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::addUser)
* userController::addUser)
* .build(); * .build();
* </pre> * </pre>
* @param pattern the pattern to match to * @param pattern the pattern to match to
@ -389,9 +388,8 @@ public abstract class RouterFunctions {
* to the {@code editUser} method in {@code userController}: * to the {@code editUser} method in {@code userController}:
* <pre class="code"> * <pre class="code">
* RouterFunction&lt;ServerResponse&gt; route = * RouterFunction&lt;ServerResponse&gt; route =
* RouterFunctions.route() * RouterFunctions.route()
* .PUT("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), * .PUT("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser)
* userController::editUser)
* .build(); * .build();
* </pre> * </pre>
* @param pattern the pattern to match to * @param pattern the pattern to match to
@ -419,9 +417,8 @@ public abstract class RouterFunctions {
* to the {@code editUser} method in {@code userController}: * to the {@code editUser} method in {@code userController}:
* <pre class="code"> * <pre class="code">
* RouterFunction&lt;ServerResponse&gt; route = * RouterFunction&lt;ServerResponse&gt; route =
* RouterFunctions.route() * RouterFunctions.route()
* .PATCH("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), * .PATCH("/user", RequestPredicates.contentType(MediaType.APPLICATION_JSON), userController::editUser)
* userController::editUser)
* .build(); * .build();
* </pre> * </pre>
* @param pattern the pattern to match to * @param pattern the pattern to match to
@ -483,11 +480,11 @@ public abstract class RouterFunctions {
* {@code OrderController.routerFunction()}. * {@code OrderController.routerFunction()}.
* to the {@code changeUser} method in {@code userController}: * to the {@code changeUser} method in {@code userController}:
* <pre class="code"> * <pre class="code">
* RouterFunction&lt;ServerResponse&gt; route = * RouterFunctionlt;ServerResponsegt; route =
* RouterFunctions.route() * RouterFunctions.route()
* .GET("/users", userController::listUsers) * .GET("/users", userController::listUsers)
* .add(orderController.routerFunction()); * .add(orderController.routerFunction());
* .build(); * .build();
* </pre> * </pre>
* @param routerFunction the router function to be added * @param routerFunction the router function to be added
* @return this builder * @return this builder
@ -529,10 +526,9 @@ public abstract class RouterFunctions {
* RouterFunctions.route() * RouterFunctions.route()
* .nest(RequestPredicates.path("/user"), () -> * .nest(RequestPredicates.path("/user"), () ->
* RouterFunctions.route() * RouterFunctions.route()
* .GET(this::listUsers) * .GET(this::listUsers)
* .POST(this::createUser); * .POST(this::createUser)
* .build(); * .build())
* )
* .build(); * .build();
* </pre> * </pre>
* @param predicate the predicate to test * @param predicate the predicate to test
@ -555,8 +551,7 @@ public abstract class RouterFunctions {
* RouterFunctions.route() * RouterFunctions.route()
* .nest(RequestPredicates.path("/user"), builder -> * .nest(RequestPredicates.path("/user"), builder ->
* builder.GET(this::listUsers) * builder.GET(this::listUsers)
* .POST(this::createUser); * .POST(this::createUser))
* )
* .build(); * .build();
* </pre> * </pre>
* @param predicate the predicate to test * @param predicate the predicate to test
@ -601,8 +596,7 @@ public abstract class RouterFunctions {
* RouterFunctions.route() * RouterFunctions.route()
* .path("/user", builder -> * .path("/user", builder ->
* builder.GET(this::listUsers) * builder.GET(this::listUsers)
* .POST(this::createUser); * .POST(this::createUser))
* )
* .build(); * .build();
* </pre> * </pre>
* @param pattern the pattern to match to * @param pattern the pattern to match to
@ -727,7 +721,6 @@ public abstract class RouterFunctions {
* @return the built router function * @return the built router function
*/ */
RouterFunction<ServerResponse> build(); RouterFunction<ServerResponse> build();
} }
@ -784,11 +777,11 @@ public abstract class RouterFunctions {
} }
} }
/** /**
* A composed routing function that first invokes one function, and then invokes the * A composed routing function that first invokes one function, and then invokes the
* another function (of the same response type {@code T}) if this route had * another function (of the same response type {@code T}) if this route had
* {@linkplain Mono#empty() no result}. * {@linkplain Mono#empty() no result}.
*
* @param <T> the server response type * @param <T> the server response type
*/ */
static final class SameComposedRouterFunction<T extends ServerResponse> extends AbstractRouterFunction<T> { static final class SameComposedRouterFunction<T extends ServerResponse> extends AbstractRouterFunction<T> {
@ -815,6 +808,7 @@ public abstract class RouterFunctions {
} }
} }
/** /**
* A composed routing function that first invokes one function, and then invokes * A composed routing function that first invokes one function, and then invokes
* another function (of a different response type) if this route had * another function (of a different response type) if this route had
@ -843,13 +837,12 @@ public abstract class RouterFunctions {
this.first.accept(visitor); this.first.accept(visitor);
this.second.accept(visitor); this.second.accept(visitor);
} }
} }
/** /**
* Filter the specified {@linkplain HandlerFunction handler functions} with the given * Filter the specified {@linkplain HandlerFunction handler functions} with the given
* {@linkplain HandlerFilterFunction filter function}. * {@linkplain HandlerFilterFunction filter function}.
*
* @param <T> the type of the {@linkplain HandlerFunction handler function} to filter * @param <T> the type of the {@linkplain HandlerFunction handler function} to filter
* @param <S> the type of the response of the function * @param <S> the type of the response of the function
*/ */
@ -883,8 +876,8 @@ public abstract class RouterFunctions {
} }
} }
private static final class DefaultRouterFunction<T extends ServerResponse>
extends AbstractRouterFunction<T> { private static final class DefaultRouterFunction<T extends ServerResponse> extends AbstractRouterFunction<T> {
private final RequestPredicate predicate; private final RequestPredicate predicate;
@ -915,11 +908,10 @@ public abstract class RouterFunctions {
public void accept(Visitor visitor) { public void accept(Visitor visitor) {
visitor.route(this.predicate, this.handlerFunction); visitor.route(this.predicate, this.handlerFunction);
} }
} }
private static final class DefaultNestedRouterFunction<T extends ServerResponse>
extends AbstractRouterFunction<T> { private static final class DefaultNestedRouterFunction<T extends ServerResponse> extends AbstractRouterFunction<T> {
private final RequestPredicate predicate; private final RequestPredicate predicate;
@ -952,7 +944,8 @@ public abstract class RouterFunctions {
private void mergeTemplateVariables(ServerRequest request, Map<String, String> variables) { private void mergeTemplateVariables(ServerRequest request, Map<String, String> variables) {
if (!variables.isEmpty()) { if (!variables.isEmpty()) {
Map<String, Object> attributes = request.attributes(); Map<String, Object> attributes = request.attributes();
Map<String, String> oldVariables = (Map<String, String>)request.attribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE) Map<String, String> oldVariables =
(Map<String, String>) request.attribute(RouterFunctions.URI_TEMPLATE_VARIABLES_ATTRIBUTE)
.orElseGet(LinkedHashMap::new); .orElseGet(LinkedHashMap::new);
Map<String, String> mergedVariables = new LinkedHashMap<>(oldVariables); Map<String, String> mergedVariables = new LinkedHashMap<>(oldVariables);
mergedVariables.putAll(variables); mergedVariables.putAll(variables);
@ -967,9 +960,9 @@ public abstract class RouterFunctions {
this.routerFunction.accept(visitor); this.routerFunction.accept(visitor);
visitor.endNested(this.predicate); visitor.endNested(this.predicate);
} }
} }
private static class ResourcesRouterFunction extends AbstractRouterFunction<ServerResponse> { private static class ResourcesRouterFunction extends AbstractRouterFunction<ServerResponse> {
private final Function<ServerRequest, Mono<Resource>> lookupFunction; private final Function<ServerRequest, Mono<Resource>> lookupFunction;
@ -990,6 +983,7 @@ public abstract class RouterFunctions {
} }
} }
private static class HandlerStrategiesResponseContext implements ServerResponse.Context { private static class HandlerStrategiesResponseContext implements ServerResponse.Context {
private final HandlerStrategies strategies; private final HandlerStrategies strategies;

Loading…
Cancel
Save