Creating a custom UI class?

I tried the following snippet that results in a somehow endless loop:

public class MyUI  extends UI {


    @Override
    protected void init(VaadinRequest request) {
        super.init(request);
        System.out.println("Hello UI");
    }

    @WebServlet(value = "/*", name = "vaadinServlet")
    @VaadinServletConfiguration(ui =  MyUI.class, productionMode = false)
    public static class MyServlet extends VaadinServlet {

    }
}

Any idea how I should configure a custom UI class in Vaadin Flow?
Any help will be appreciated!

Strangewise we found that

public class MyUI  extends UI {


    @Override
    protected void init(VaadinRequest request) {
        System.out.println("Hello UI");
    }

    @WebServlet(urlPatterns = "/*", name = "vaadinServlet", asyncSupported = true)
//    @VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
    public static class MyServlet extends VaadinServlet {

    }
}

leaving out the VaadinServletConfiguration makes it work! (?)

I think your first example should work, and I see no endless loop when using it. Do you have something else in your app which might explain the problem? Otherwise, have a look at e.g. what jstack says