Interface RouterFactory

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface RouterFactory
Factory for creating Router instances.

A factory is resolved in the following order:

  1. A RouterFactory set on the SeBootstrap.Configuration via the PROPERTY property
  2. A RouterFactory discovered via ServiceLoader
  3. A default factory that creates a plain Router via Router.router(Vertx)

Configuration property

A factory can be provided per-startup via SeBootstrap.Configuration. Since RouterFactory is a FunctionalInterface, a lambda can be used:

Configuration config = Configuration.builder()
        .property(RouterFactory.ROUTER_FACTORY, (RouterFactory) vertx -> {
            Router router = Router.router(vertx);
            router.route().handler(CorsHandler.create());
            return router;
        })
        .build();
SeBootstrap.start(MyApplication.class, config);

ServiceLoader

A global default factory can be registered by placing a file named META-INF/services/dev.resteasy.vertx.server.spi.RouterFactory on the classpath containing the fully qualified class name of the implementation:

public class MyRouterFactory implements RouterFactory {
    public Router create(Vertx vertx) {
        Router router = Router.router(vertx);
        router.route().handler(CorsHandler.create());
        return router;
    }
}
Author:
James R. Perkins
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    A property name used to reference a RouterFactory placed in the configuration.
  • Method Summary

    Modifier and Type
    Method
    Description
    io.vertx.ext.web.Router
    create(io.vertx.core.Vertx vertx)
    Creates or returns a Router instance.
  • Field Details

  • Method Details

    • create

      io.vertx.ext.web.Router create(io.vertx.core.Vertx vertx)
      Creates or returns a Router instance.
      Parameters:
      vertx - the Vert.x instance
      Returns:
      the router