Spring Boot Tomcat 容器部署错误
Posted
技术标签:
【中文标题】Spring Boot Tomcat 容器部署错误【英文标题】:Spring Boot Tomcat Container Deployment Errors 【发布时间】:2015-02-06 07:48:04 【问题描述】:我想将我的 Spring Boot 应用程序作为 WAR 部署到 Tomcat 容器,但 Tomcat 无法启动容器。我遵循了 Spring Boot Reference 中的文档Traditional Deployment Section。容器的线程大小设置为 -Xss 4068,但我仍然遇到堆栈溢出错误。
这是堆栈跟踪:
Dec 08, 2014 12:01:13 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(C:\Tomcat\customer\webapps\customer-site-0.0.1-SNAPSHOT\WEB-
INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2.
Offending class: javax/servlet/Servlet.class
Dec 08, 2014 12:01:15 AM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[customers-prototype.mydomain.com].StandardContext[/customer-site-0.0.1-SNAPSHOT]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.IllegalStateException: Unable to complete the scan for annotations for web application [/customer-site-0.0.1-SNAPSHOT] due to a ***Error. Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies. The class hierarchy being processed was [com.ibm.db2.jcc.am.mf->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object->java.lang.Object]
at org.apache.catalina.startup.ContextConfig.checkHandlesTypes(ContextConfig.java:2126)
at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2072)
at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1947)
at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1913)
at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1898)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1330)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:889)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:386)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5380)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 11 more
Dec 08, 2014 12:01:15 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive C:\Tomcat\customer\webapps\customer-site-0.0.1-SNAPSHOT.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component
[StandardEngine[Catalina].StandardHost[customers-prototype.mydomain.com].StandardContext[/customer-site-0.0.1-SNAPSHOT]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:649)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1081)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1877)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
Dec 08, 2014 12:01:15 AM org.apache.catalina.startup.HostConfig deployWAR
我的 pom.xml 具有以下 Spring Boot 依赖项,其中 spring-boot-starter-tomcat 范围设置为 provided,如文档中所述。
POM.XML
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>$spring.security.version</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>$spring.security.version</version>
</dependency>
更新:额外的 pom 依赖:
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc4</artifactId>
<version>9.7.0.9</version>
</dependency>
<dependency>
<groupId>com.ibm.db2</groupId>
<artifactId>db2jcc_license</artifactId>
<version>9.7.0.9</version>
</dependency>
我的主类扩展了文档中描述的 SpringBootServletInitializer:
CustomerSiteMain.java:
@Configuration
@ComponentScan("com.mydomain")
@EnableAutoConfiguration
public class CustomerMain extends SpringBootServletInitializer
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application
.showBanner(true)
.parent(Global.class)
.sources(CustomerMain.class)
.profiles("container");
public static void main(String[] args)
SpringApplication.run(CustomerMain.class, args);
@Bean
@Profile(CustomerSiteProfiles.STANDALONE)
public ServletRegistrationBean h2Console()
ServletRegistrationBean reg = new ServletRegistrationBean(new WebServlet(), "/console/*");
reg.setLoadOnStartup(1);
return reg;
@Bean
public ServletRegistrationBean servletRegistrationBean()
return new ServletRegistrationBean(new PhotoSheetPDFServlet(), "/items/factsheet/*");
【问题讨论】:
“com.ibm.db2.jcc.am.mf”从何而来?您能否展示您的 pom 中添加该依赖项的部分? @BrianClozel 那是 DB2 JDBC 驱动程序。我在代码的 pom 部分添加了额外的依赖信息。 【参考方案1】:以上内容也帮助了我。我遇到了类似的问题,并不断收到这样的 WebappClassLoader 日志:
2015-03-06 20:32:53,741 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0/WEB-INF/lib/tomcat-embed-core-8.0.15.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
2015-03-06 20:32:53,742 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(/usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0/WEB-INF/lib/tomcat-embed-el-8.0.15.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
这是我在加载 Web 应用程序时遇到的这个严重错误的线索。
2015-03-06 20:32:54,704 org.apache.catalina.startup.HostConfig deployWAR SEVERE: Error deploying web application archive /usr/local/apache-tomcat-7.0.54/webapps/gs-producing-web-service-0.1.0.war
在我的案例中,我正在开发一个 Web 服务,而我的 pom.xml 中的这些依赖项(Web 服务不是 Web)
<dependencies>
<!-- tag::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
<!-- end::springws[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
但我忘记在安装 maven 之前也进行清理。这花了我几个小时,因为我的 tomcat 库还在那里。 用户请注意,当您关注 Springs https://spring.io/guides/gs/convert-jar-to-war/ 和 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file 时,您还应该进行 maven clean
这对于更快速的开发来说非常有用。谢谢
【讨论】:
【参考方案2】:您的 Tomcat 似乎正在尝试加载一些已加载的类。 尝试从 spring-boot-starter-web 依赖项中排除嵌入的 tomcat
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
【讨论】:
以上是关于Spring Boot Tomcat 容器部署错误的主要内容,如果未能解决你的问题,请参考以下文章
多个Spring Boot项目部署在一个Tomcat容器无法启动