我正在使用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?
由于
答案 0 :(得分:0)
我无法发表评论。因此,如果您使用嵌入式tomcat,则不需要Tomcat依赖项(spring-boot-starter-tomcat),因为它已经内置了&#34; spring-boot-starter-web&#34;。尝试删除此依赖项。
答案 1 :(得分:0)
我遇到了同样的问题,通过更换端口解决了这个问题。
当我将应用程序作为Spring Application运行时,我通常使用端口9000和9001进行管理,但是当我尝试在Tomcat上运行它时,它失败并发布了相同的异常。将application.properties中的两个端口更改为8080解决了这个问题。
答案 2 :(得分:0)
就我而言,我正在运行此命令
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