Example usage for org.springframework.web.reactive DispatcherHandler DispatcherHandler

List of usage examples for org.springframework.web.reactive DispatcherHandler DispatcherHandler

Introduction

In this page you can find the example usage for org.springframework.web.reactive DispatcherHandler DispatcherHandler.

Prototype

public DispatcherHandler() 

Source Link

Document

Create a new DispatcherHandler which needs to be configured with an ApplicationContext through #setApplicationContext .

Usage

From source file:playground.Application.java

public static void main(String[] args) throws Exception {

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("playground");
    DispatcherHandler dispatcherHandler = new DispatcherHandler();
    dispatcherHandler.setApplicationContext(context);

    HttpServer server = new ReactorHttpServer();
    server.setPort(8080);/*from w  ww  . j a va  2 s .  com*/
    server.setHandler(dispatcherHandler);
    server.afterPropertiesSet();
    server.start();

    CompletableFuture<Void> stop = new CompletableFuture<>();
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        stop.complete(null);
    }));

    synchronized (stop) {
        stop.wait();
    }

}

From source file:playground.app.Application.java

public static HttpHandler createHttpHandler() throws IOException {
    Properties prop = new Properties();
    prop.load(Application.class.getClassLoader().getResourceAsStream("application.properties"));
    String profiles = prop.getProperty("profiles");
    if (profiles != null) {
        System.setProperty("spring.profiles.active", profiles);
    }/* w ww.j  a  v a2  s. c o m*/

    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext("playground");

    DispatcherHandler dispatcherHandler = new DispatcherHandler();
    dispatcherHandler.setApplicationContext(context);

    Map<String, WebFilter> beanNameToFilters = context.getBeansOfType(WebFilter.class);
    WebFilter[] filters = beanNameToFilters.values().toArray(new WebFilter[0]);
    Arrays.sort(filters, AnnotationAwareOrderComparator.INSTANCE);

    return WebHttpHandlerBuilder.webHandler(dispatcherHandler)
            .exceptionHandlers(new ResponseStatusExceptionHandler()).filters(filters).build();
}