VaadinServiceInitListener isn't invoked on startup

I’m attempting to have a bootstrap code that will be invoked upon startup and register when a user closes a browser window or log out, however the serviceInit never seems to be invoked
the app is used in jetty maven plugin and I’ve already created the spi file with class name, (as I’m not using spring) is there something I’m missing?

@Theme
@Push
public class AppShell implements AppShellConfigurator, VaadinServiceInitListener {
    @Override
    public void serviceInit(ServiceInitEvent event) {
        event.getSource().addSessionDestroyListener((SessionDestroyListener) event1 -> {
            final VaadinSession session = event1.getSession();
            final CommClient commClient = session.getAttribute(CommClient.class);
            try {
                commClient.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                session.setAttribute(CommClient.class, null);
            }
        });
    }

    @Override
    public void configurePage(AppShellSettings settings) {
        AppShellConfigurator.super.configurePage(settings);       
    }
}

Hi @Elhanan,

Assuming you followed these instructions and the listener is indeed being registered, then I would check if the closeIdleSessions property is set to true as the listener you are trying to add will only trigger when a session is destroyed.

Another useful check would be to put a log statement or breakpoint to verify if the serviceInit method is indeed, not being invoked.

i’ve already placed a breakpoint on the serviceInit, that’s why i know it’s not being invoked.
i’m wondering about SPI configuration, is really being used here, because it’s still operated as a war right?

In a plain Java servlet Vaadin application,VaadinServiceInitListeners are loaded using ServiceLoder API.
So, if you have put the correct class name in META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener, it should work.

If your setup is correct and the listener is not executed, could you please share a minimal reproducible example project?

OH , dang my eyes, i see the issue , the FILENAME should be VaadinServiceInitListener while it’s contents should be the the actual contents should be my class.

1 Like