I have completed my Vaadin application. It is working almost as expected in my IDE. Now I need to deploy it to the production server to the Tomcat container. I have changed packaging to WAR and followed instructions on https://vaadin.com/docs/latest/production/spring-boot
However, when I dropped resulting war file into webapps directory on the tomcat server v.9.0.72 it was unpacked but won't start. When I looked into the tomcat logs I did find the following exception stacktrace:
27-Feb-2023 06:49:12.915 SEVERE [Catalina-utility-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/opt/tomcat/apache-tomcat-9.0.72/webapps/encyclopediaView.war] java.lang.IllegalStateException: Error starting child at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:686) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:658) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:662) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1023) at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1910) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.base/java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:123) at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:824) at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474) at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1666) at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:314) at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123) at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1102) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1301) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1305) at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1283) at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305) at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/encyclopediaView]] at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:683) ... 24 more Caused by: java.lang.NoSuchMethodError: 'org.springframework.web.context.WebApplicationContext org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(javax.servlet.ServletContext)' at com.vaadin.flow.spring.SpringLookupInitializer.getApplicationContext(SpringLookupInitializer.java:188) at com.vaadin.flow.spring.SpringLookupInitializer.initialize(SpringLookupInitializer.java:150) at com.vaadin.flow.server.startup.LookupServletContainerInitializer.process(LookupServletContainerInitializer.java:105) at com.vaadin.flow.server.startup.ClassLoaderAwareServletContainerInitializer.lambda$onStartup$2(ClassLoaderAwareServletContainerInitializer.java:81) at com.vaadin.flow.server.startup.ClassLoaderAwareServletContainerInitializer.onStartup(ClassLoaderAwareServletContainerInitializer.java:122) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4929) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) ... 25 more
I did check dependencies and Spring framework documentation and method WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) does exist in this class.
Please do tell me what I am doing wrong and how to fix it. I am using Vaadin 23.3.6 and Java 18
I did follow Tatu's advice and downgraded SpringBoot to version 2.7.3. Now I am getting completely different error:
java.lang.IllegalStateException: Error starting child at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:686) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:658) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:662) at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1023) ... Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ... 47 more
Caused by:Failed to determine a suitable driver class at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:182)org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:
The problem is that I am not using DataSource in my Vaadin application. I am using REST API calls to get my data. What driver it asking for than? I did placed MySQL JDBC driver mysql-connector-java-8.0.30.jar to the Tomcat /lib directory, but it didn't change anything.
In a nutshell (as @tatu-lund stated above), up through Vaadin 23, Spring 5/Spring Boot 2.7, and Tomcat 9, Java EE packages are used. The switch to use Jakarta packages happened with Vaadin 24, Spring 6/Spring Boot 3, and Tomcat 10.