0

I've got a Vaadin 14 application (with Spring Boot) and want to do execute some code when the server is fully started and the frontend is compiled, up and running.

Putting the code into a @Component in the method afterPropertiesSet() does not work, because this is executed far before Vaadins frontend compilation.

Pulling for the login view (= http://localhost:8080/login returns a HTTP status equal to 200=OK) works, but this seems to be not the elegant way of doing this.

Question: what is the elegant way of waiting for Vaadin startup?

  • 1
    Interesting question. But why is it necessary for the server-side service to wait for the frontend to be ready? – Twistleton Jan 17 '21 at 16:24
  • Good question. After thinking over it again it seems that my question was wrong. Restated question and the answer to that you find at https://stackoverflow.com/questions/65753686/wait-for-vaadin-server-startup#comment116303889_65770981 –  Jan 18 '21 at 19:00

1 Answers1

2

I would like to understand the usecase for this.

because this is executed far before Vaadins frontend compilation

Frontend compilation is done in runtime ONLY in dev mode which you should not use in the production environment. Dev mode is intended to be used to speed up the development and it's initially not elegant way of doing things (like extra process to start which is needed only once). If you Vaadin app in production then all the frontend resources should be pre-compiled using maven plugin. In the latter case Vaadin app is started as any other web application. So is it really necessary to wait for frontend compilation within the dev mode ?

  • 1
    There are two use cases: (a) start Selenium test cases (system is started with @SpringBootTest and pulls for localhost:8080/login) and (b) send emails to users/admins in the prod system to inform them about the (full) restart (e.g. after a maintenance pause). You're right: there is no frontend compilation in the productive case (b) - I mixed things up here with (a) - and the waiting time has to be something else. So my question should have been "how can I execute code when my application is ready to serve?" and the answer is this one: https://stackoverflow.com/a/38668148/14972917 Thank you! –  Jan 18 '21 at 18:50
  • 2
    For the Vaadin specific things you may use `VaadinServiceInitListener` : it's called when `VaadinService` is initialized (more specific than web app readiness) – Denis Anisimov Jan 19 '21 at 10:12
  • 2
    `@Component public class MyUIServiceInitListener implements VaadinServiceInitListener {@Override public void serviceInit(ServiceInitEvent event) {/*doing my stuff here*/}}` works like a charm for my production use case. Great. Thank you! :-) –  Jan 21 '21 at 07:30