Charbel
Charbel

Reputation: 14697

When I connect to my Vaadin application from 2 tabs I get: "Error This UI instance is already initialized"

I'm adding Vaadin to an existing Spring application. I added a UI, and a grid and a couple other components.

I noticed that when I load first time it works fine, but if I connect another browser page or reload, than I get an error:

"error":"Internal Server Error","exception":"com.vaadin.server.ServiceException","message":"java.lang.IllegalStateException: This UI instance is already initialized (as UI id 0) and can therefore not be initialized again (as UI id 2). Please make sure you are not accidentally reusing an old UI instance."

I wasn't sure how to register my UI in Spring, so I created a @Bean method in the Spring Java config file of my application:

@Bean
    MainUI ui() {
        MainUI ui = new MainUI (mainController());
        return ui;
    }

I suspect the issue is that there is a single instance of this bean? can you please explain how that can be fixed?

Upvotes: 0

Views: 225

Answers (2)

Charbel
Charbel

Reputation: 14697

The answer to the above is using the below for the XxxUI class (annotated with @SpringUI):

@Bean
@Scope("prototype") 

Upvotes: 0

Henri Kerola
Henri Kerola

Reputation: 4967

In your example, you create a singleton MainUI bean, which is shared by all users of the application. Usually, a UI instance represents a browser tab, and for each active tab for each user, there should be its own UI instance.

If you want to use Vaadin with Spring you should use the Vaadin Spring or Vaadin Spring Boot addon.

Upvotes: 1

Related Questions