spring
spring copied to clipboard
Multiple Vaadin Spring servlets not supported
We have multiple Vaadin servlets in a single "web application" (i.e. defined in the same deployment descriptor). We are using the Vaadin Spring add-on. Thus, we have multiple UIs annotated with @SpringUI in the same Spring application context. We recently encountered the following problem:
When the SpringUIProvider attempts to detect the UIs in the Spring application context, it discovers all UIs in the Spring application context. There is, as far as we know, no mechanism for designating which UIs are relevant.
This causes all UIs to be mapped to the same path (e.g. /applicationA if the servlet corresponding to the path /applicationA is currently initializing).
If we use the path parameter of the @SpringUI annotation to enforce unique paths, then this ruins our desired path structure, since applications can then be accessed via the path of any other servlet and there is no longer a unique path (e.g. /applicationA/applicationB and /applicationB/applicationA will access the same UI).
In other words, we actually desire the strategy defined in DefaultUIProvider.
Unfortunately, the SpringVaadinServlet registers the SpringUIProvider with the highest precedence in the UIProvider chain, and thus we cannot simply add our own UIProvider or suppress the SpringUIProvider in any convenient manner.
Our temporary solution is to subclass SpringVaadinServlet, override servletInitialized() with an empty method (since the superclass method only removes any DefaultUIProvider and adds the SpringUIProvider). We also register a custom UI provider that instantiates beans via Spring (thus doing essentially the same thing as the SpringUIProvider but with a different strategy for discovering the UI).
There should be a way to do what we want without the custom work. Why the SpringVaadinServlet does not respect it's UI init parameter is beyond us but we believe if this parameter is present the servlet should respect it and limit its search to only UIs of the specified type.
Same probleme here. Is everybody with Vaading and Spring using only one servlet?
thank you for your code, it does the trick.