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.
Factory for creating
Router instances.
A factory is resolved in the following order:
- A
RouterFactoryset on theSeBootstrap.Configurationvia thePROPERTYproperty - A
RouterFactorydiscovered viaServiceLoader - A default factory that creates a plain
RouterviaRouter.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
FieldsModifier and TypeFieldDescriptionstatic final StringA property name used to reference aRouterFactoryplaced in the configuration. -
Method Summary
Modifier and TypeMethodDescriptionio.vertx.ext.web.Routercreate(io.vertx.core.Vertx vertx) Creates or returns aRouterinstance.
-
Field Details
-
PROPERTY
A property name used to reference aRouterFactoryplaced in the configuration.- See Also:
-
-
Method Details
-
create
io.vertx.ext.web.Router create(io.vertx.core.Vertx vertx) Creates or returns aRouterinstance.- Parameters:
vertx- the Vert.x instance- Returns:
- the router
-