Hi,
We are in a bit of a pickle trying to add a Vaadin module to an existing Spring / Tomcat application.
Imaging there is an app module, which is deployed on Tomcat, and uses Spring for some basic DI. Ideally I want to add a ui-module to this application. The app should work perfectly without it, but when the ui dependency is added, we want the Vaadin based ui to also work.
I tried registering the VaadinServlet to the ServletContext programmatically.
I also added a @Configuration class with @EnableVaadin on it.
The servlet registration appears to be working, however I get the following exception:
java.lang.IllegalStateException: The application Lookup instance is not found in VaadinContext. The instance is supposed to be created by a ServletContainerInitializer. Issues known to cause this problem are:
- A Spring Boot application deployed as a war-file but the main application class does not extend SpringBootServletInitializer
- An embedded server that is not set up to execute ServletContainerInitializers
- Unit tests which do not properly set up the context for the test
at com.vaadin.flow.server.startup.ApplicationConfiguration.lambda$get$0(ApplicationConfiguration.java:53)
at com.vaadin.flow.server.VaadinServletContext.getAttribute(VaadinServletContext.java:73)
at com.vaadin.flow.server.startup.ApplicationConfiguration.get(ApplicationConfiguration.java:47)
at com.vaadin.flow.server.DeploymentConfigurationFactory.createPropertyDeploymentConfiguration(DeploymentConfigurationFactory.java:73)
at com.vaadin.flow.server.startup.ServletDeployer$StubServletConfig.createDeploymentConfiguration(ServletDeployer.java:139)
at com.vaadin.flow.server.startup.ServletDeployer.lambda$getServletConfigurations$0(ServletDeployer.java:198)
at java.base/java.util.Optional.ifPresent(Optional.java:178)
at com.vaadin.flow.server.startup.ServletDeployer.getServletConfigurations(ServletDeployer.java:197)
at com.vaadin.flow.server.startup.ServletDeployer.contextInitialized(ServletDeployer.java:148)
at com.vaadin.flow.server.startup.ServletContextListeners.contextInitialized(ServletContextListeners.java:44)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4452)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4890)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:171)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:683)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:658)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:712)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1796)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:293)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:803)
It feels like Tomcat is initializing things it shouldn’t.
Any ideas how I could get this working?
I have pushed my current state of trial-and-error to GitHub.
Btw, I already know what most of you are thinking … “why not simply use Spring Boot?”.
We’ll be having that discussion internally later … but for now, I’m stuck with the current stack.
All suggestions are greatly appreciated
Kind regards,
Kristof.