Vaadin application deployed to Tomcat 无法启动

huangapple go评论69阅读模式
英文:

Vaadin application deployed to tomcat can't start

问题

我已经完成了我的Vaadin应用程序。在我的IDE中几乎按预期工作。

现在我需要将其部署到生产服务器上的Tomcat容器中。我已将打包方式更改为WAR,并按照https://vaadin.com/docs/latest/production/spring-boot 上的说明进行了操作。

然而,当我将生成的war文件放入Tomcat服务器 v.9.0.72中的webapps目录时,它被解压但无法启动。当我查看了Tomcat日志时,我发现了以下异常堆栈跟踪:

27-Feb-2023 06:49:12.915 严重 [Catalina-utility-1]
org.apache.catalina.startup.HostConfig.deployWAR 部署Web应用程序存档时出错
[/opt/tomcat/apache-tomcat-9.0.72/webapps/encyclopediaView.war]
java.lang.IllegalStateException: 启动子组件时出错 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)

原因是:org.apache.catalina.LifecycleException: 无法启动组件
[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 由于: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

我已经检查了依赖项和Spring框架文档,发现了方法 WebApplicationContext getRequiredWebApplicationContext(ServletContext sc) 在这个类中确实存在。

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html

请告诉我我做错了什么以及如何修复它。

我正在使用 Vaadin 23.3.6 和 Java 18。

我确实遵循了Tatu的建议,将SpringBoot降级到了版本2.7.3。现在我得到了完全不同的错误:

java.lang.IllegalStateException: 启动子组件时出错 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)
... 由于:
org.springframework.beans.BeanInstantiationException: 无法实例化[org.apache.tomcat.jdbc.pool.DataSource]:
工厂方法'dataSource'引发异常;嵌套异常是
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException:
无法确定合适的驱动程序类 at
org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at
org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 47 more 由于:

无法确定合适的驱动程序类 at
org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:182)org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException

英文:

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.

https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/context/support/WebApplicationContextUtils.html

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.

答案1

得分: 2

Vaadin 23 不支持 Servlet 5+ API,因此无法与 Spring Framework 6 和 Spring Boot 3 一起使用。
必须使用 Spring Boot 2.7 和 Spring Framework 5,或者升级到 Vaadin 24,它面向 Servlet 5+ 和 Spring Boot 3.0 或更新的版本。

由于 WebApplicationContextUtils.getWebApplicationContext 方法接受 jakarta.servlet.ServletContext,但实际参数是 javax.servlet.ServletContext,所以找不到该方法。

英文:

Vaadin 23 does not support servlet 5+ api, so it cannot be used with spring framework 6 and spring boot 3.
You have to use Spring boot 2.7 and spring framework 5. Or alternatively upgrade to Vaadin 24 which is targeted to Servlet 5+ and Spring Boot 3.0 or newer.

The WebApplicationContextUtils.getWebApplicationContext method is not found because it takes a jakarta.servlet.ServletContext, but the actual argument is javax.servlet.ServletContext

答案2

得分: 0

简而言之,截止到 Vaadin 23、Spring 5/Spring Boot 2.7 和 Tomcat 9,使用的是 Java EE 包。切换到使用 Jakarta 包是从 Vaadin 24、Spring 6/Spring Boot 3 和 Tomcat 10 开始的。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月27日 16:11:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/75578074.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定