![](/img/trans.png)
[英]Spring Boot: WebServerException: Unable to start embedded Tomcat
[英]Unable to start embedded tomcat Spring boot
我正在開發 Spring Boot Gradle 應用程序。 當我嘗試通過執行 booRun 將其作為戰爭運行時,我的應用程序拋出錯誤。 錯誤說:無法啟動嵌入式 tomcat。 build.gradle 文件的內容:
group 'com.example'
version '1.0-SNAPSHOT'
bootRepackage {
mainClass = 'com.ex.MainClass'
}
apply plugin: 'war'
apply plugin: 'propdeps'
war {
baseName = 'abc'
archiveName 'abc.war'
}
repositories{
// mavenLocal()
mavenCentral()
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("io.springfox:springfox-swagger2:2.7.0")
compile("io.springfox:springfox-swagger-ui:2.7.0")
compile fileTree(dir:"lib", include:"*.jar")
compile('org.springframework.boot:spring-boot-starter-mail')
optional("org.springframework.boot:spring-boot-configuration-processor")
compile("org.springframework.boot:spring-boot-starter-tomcat")
compile "io.springfox:springfox-swagger2:2.7.0"
compile 'io.springfox:springfox-swagger-ui:2.7.0'
compile("org.springframework.boot:spring-boot-starter-amqp")
}
compileJava.dependsOn(processResources)
整個堆棧跟蹤如下:
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-4.3.8.RELEASE.jar:4.3.8.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at com.ex.MainClass.main(MainClass.java:38) [main/:na]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:123) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:84) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:554) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:179) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
... 8 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.startup.Tomcat.start(Tomcat.java:344) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE]
... 13 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:793) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
... 15 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
... 17 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:947) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.14.jar:8.5.14]
... 19 common frames omitted
bootRun FAILED
編輯:添加主類定義:
@SpringBootApplication
@EnableAsync
@EnableCaching
@EnableScheduling
public class MainClass extends SpringBootServletInitializer {
public static final Logger logger = LoggerFactory.getLogger(MainClass.class);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainClass.class);
}
public static void main(String[] args) {
SpringApplication.run(MainClass.class, args);
}
}
誰能告訴我為什么我的應用程序無法在嵌入式 tomcat 上啟動?
謝謝
我無法發表評論。 因此,如果您使用的是嵌入式 tomcat,則不需要 Tomcat 依賴項(spring-boot-starter-tomcat),因為它已經內置了“spring-boot-starter-web”。 嘗試刪除此依賴項。
我遇到了同樣的問題,通過更換端口解決了。
當我將應用程序作為 Spring Application 運行時,我通常使用端口 9000 和 9001 進行管理,但是當我嘗試在 Tomcat 上運行它時,它失敗了,出現了與您發布的相同的異常。 將 application.properties 中的兩個端口更改為 8080 解決了這個問題。
就我而言,我正在運行此命令
mvn spring-boot:run -Dmaven.tomcat.port=8081 -Dspring.config.location=file:[Project Root Dir]\src\main\resources -Dspring.profiles.active=dev -DskipTests > log.log
原來我只是忘了在末尾添加反斜杠
\src\main\resources
因此它找不到配置文件。
對我來說修復就是這樣,所以我現在有以下代碼。
mvn spring-boot:run -Dmaven.tomcat.port=8081 -Dspring.config.location=file:[Project Root Dir]\src\main\resources\ -Dspring.profiles.active=dev -DskipTests > log.log
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.