VaadinServiceInitListener

A VaadinServiceInitListener can be used to configure RequestHandlers, BootstrapListeners and DependencyFilters.

The listener should be added to a ServiceInitEvent which is sent when a Vaadin service is initialized.

Java

  1. public class ApplicationServiceInitListener
  2. implements VaadinServiceInitListener {
  3. @Override
  4. public void serviceInit(ServiceInitEvent event) {
  5. event.addBootstrapListener(response -> {
  6. // BoostrapListener to change the bootstrap page
  7. });
  8. event.addDependencyFilter((dependencies, filterContext) -> {
  9. // DependencyFilter to add/remove/change dependencies sent to
  10. // the client
  11. return dependencies;
  12. });
  13. event.addRequestHandler((session, request, response) -> {
  14. // RequestHandler to change how responses are handled
  15. return false;
  16. });
  17. }
  18. }

This listener should be registered as a provider via Java SPI loading facility. To do this you should create META-INF/services resource directory and a provider configuration file with the name com.vaadin.flow.server.VaadinServiceInitListener. This is a text file and it should contain the fully qualified name of the ApplicationServiceInitListener class on its own line. It allows to discover the ApplicationServiceInitListener class, instantiate it and register as a service init listener for the application.

The location of the configuration file

The content of the file should be like this:

text

  1. com.mycompany.ApplicationServiceInitListener
Tip
See https://docs.oracle.com/javase/tutorial/ext/basics/spi.html#register-service-providers and https://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html for details about Java SPI loading.