> Markdown version of [Service Init Listener](https://vaadin.com/docs/v14/flow/advanced/tutorial-service-init-listener). Section index: [llms.txt](https://vaadin.com/docs/v14/flow/llms.txt)

# Service Init Listener

`VaadinServiceInitListener` can be used to configure `RequestHandlers`, [`BootstrapListeners`](https://vaadin.com/docs/v14/flow/advanced/tutorial-bootstrap.md) and [`DependencyFilters`](https://vaadin.com/docs/v14/flow/advanced/tutorial-dependency-filter.md). You can also use it to [dynamically register routes during the application startup](https://vaadin.com/docs/v14/flow/routing/tutorial-router-dynamic-routes.md#application.startup).

The listener gets a `ServiceInitEvent` which is sent when a Vaadin service is initialized.

```java
public class ApplicationServiceInitListener
        implements VaadinServiceInitListener {

    @Override
    public void serviceInit(ServiceInitEvent event) {
        event.addBootstrapListener(response -> {
            // BoostrapListener to change the bootstrap page
        });

        event.addDependencyFilter((dependencies, filterContext) -> {
            // DependencyFilter to add/remove/change dependencies sent to
            // the client
            return dependencies;
        });

        event.addRequestHandler((session, request, response) -> {
            // RequestHandler to change how responses are handled
            return false;
        });
    }

}
```

In a Spring Boot project, it is sufficient to register this listener by adding the `@Component` annotation on the class. In plain Java projects, the 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.

[Image: The location of the configuration file]

The content of the file should be like this:

```text
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.

`0AE4EA98-6E2B-4F32-BD5D-1ACE29329322`
