无法启动嵌入式容器 Spring Boot Application org.apache.catalina.LifecycleException:子容器在启动期间失败
Posted
技术标签:
【中文标题】无法启动嵌入式容器 Spring Boot Application org.apache.catalina.LifecycleException:子容器在启动期间失败【英文标题】:Unable to start embedded container Spring Boot Application org.apache.catalina.LifecycleException: A child container failed during start 【发布时间】:2016-12-29 00:37:17 【问题描述】:尝试使用 Gradle 运行 mvc spring boot 应用程序,我只想使用以下类启动 Spring boot 项目: build.gradle
buildscript
ext
springBootVersion = '1.4.0.RELEASE'
rdf4jVersion = '2.0'
// tomcat.version = '7.0.59'
repositories
maven url "http://repo.spring.io/libs-milestone"
mavenLocal()
mavenCentral()
dependencies
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
//ext['tomcat.version'] = '9.0.0.M9'
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
war
baseName = 'eat-basic'
version = '0.0.1'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories
mavenLocal()
mavenCentral()
dependencies
/* =====================*/
/* SPRING BOOT */
/* =====================*/
compile(group: 'org.springframework.boot', name: 'spring-boot-starter')
exclude(module: 'commons-logging')
exclude(module: 'servlet-api')
exclude(group: 'org.springframework.boot', module: 'spring-boot-starter-logging')
compile (group: 'org.springframework.boot', name: 'spring-boot-starter-web')
exclude(module: 'servlet-api')
/*Other Spring boot dependency*/
compile (group: 'org.springframework.boot', name: 'spring-boot-devtools')
exclude(module: 'servlet-api')
/*Optional Spring boot */
compile (group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc')
exclude(module: 'servlet-api')
compile (group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa')
exclude(module: 'servlet-api')
compile (group: 'org.springframework.boot', name: 'spring-boot-starter-jooq')
exclude(module: 'servlet-api')
testCompile(group: 'org.springframework.boot', name:'spring-boot-starter-test')
exclude(module: 'commons-logging')
exclude(module: 'servlet-api')
/* =============================*/
/* Required dependency for JSP */
/* =============================*/
compile (group: 'javax.servlet', name: 'jstl')
exclude(module: 'servlet-api')
/*include from spring boot plugin */
compile group: 'javax.servlet', name: 'servlet-api' /*include from spring boot plugin */
compile (group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper')
exclude(module: 'servlet-api')
/*include from spring boot plugin*/
compile (group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core')
exclude(module: 'servlet-api')
/*include from spring boot plugin*/
compile(group: 'javax.servlet.jsp', name: 'javax.servlet.jsp-api', version: '2.3.2-b02')
exclude(module: 'servlet-api')
compile group: 'javax.servlet', name: 'servlet-api', version: '2.5'
/* ====================== */
/* LOGGING */
/* ====================== */
compileOnly 'org.slf4j:slf4j-api:1.7.21'
/* log4j-over-slf4j + jul-to-slf4j + jcl-over-slf4j + logback-classic*/
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-logging', version: '1.4.0.RELEASE')
exclude(group: 'ch.qos.logback', module:'logback-classic')
compile (group: 'ch.qos.logback', name: 'logback-classic', version: '1.1.7')
exclude group: 'org.slf4j'
eclipse
classpath
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
Application.java
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer
private static final org.slf4j.Logger logger =
org.slf4j.LoggerFactory.getLogger(Application.class);
public static String FOLDER = "default";
public static void main(String[] args)
logger.info("EAT Playground\n");
if (args.length > 0)
String folderAux = args[0];
if (new File(folderAux).exists())
FOLDER = folderAux;
else logger.info(folderAux + " folder not found");
logger.info("Reading from " + FOLDER);
SpringApplication.run(Application.class, args);
String port;
if (System.getProperty("server.port") == null)
port = "8080";
logger.info("Taking default port 8080. The value of the port can be changed, by adding the jvm option: -Dserver.port=8090");
else
port = System.getProperty("server.port");
logger.info("server.port option found. Taking port " + port);
String serverUrl = "http://localhost:" + port; // path to your new file
logger.info("Server started at " + serverUrl);
@Bean
public CacheManager cacheManager()
return new ConcurrentMapCacheManager("asset", "queries", "faqs", "page", "page-tree");
private Set<ErrorPage> pageHandlers;
@PostConstruct
private void init()
pageHandlers = new HashSet<>();
pageHandlers.add(new ErrorPage(HttpStatus.NOT_FOUND,"/notfound.html"));
pageHandlers.add(new ErrorPage(HttpStatus.FORBIDDEN,"/forbidden.html"));
/**
* Method to adding a web application to Tomcat's web apps directory"
* @return the @link EmbeddedServletContainerFactory
*/
@Bean
public EmbeddedServletContainerFactory servletContainerFactory()
return new TomcatEmbeddedServletContainerFactory()
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(
Tomcat tomcat)
try
logger.info("Setting custom configuration for Mainstay:");
//tomcat.setPort(Integer.valueOf(port));
//tomcat.setContextPath(context);
//tomcat.setErrorPages(pageHandlers);
tomcat.addWebapp("/workbench", "/war/rdf4j-workbench.war");
tomcat.addWebapp("/server", "/war/rdf4j-server.war");
catch (ServletException ex)
throw new IllegalStateException("Failed to add webapp", ex);
return super.getTomcatEmbeddedServletContainer(tomcat);
;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(Application.class);
@Override
public void onStartup(ServletContext servletContext) throws ServletException
SpringApplication.run(Application.class);
CacheConfigurarion.java
Configuration
@EnableCaching
@Profile("!nocache")
public class CacheConfiguration
WebConfig.java
@Configuration
public class WebConfig extends WebMvcConfigurationSupport
@Override
protected void addResourceHandlers(ResourceHandlerRegistry registry)
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
@Override
protected void addViewControllers(ViewControllerRegistry registry)
registry.addViewController("/").setViewName("forward:/index.html");
@Bean
public InternalResourceViewResolver defaultViewResolver()
return new InternalResourceViewResolver();
...当我尝试在 Application 上运行程序时,我在代码段 return super.getTomcatEmbeddedServletContainer(tomcat);
处收到以下异常:
org.springframework.context.ApplicationContextException:无法启动嵌入式容器;嵌套异常是 org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) 在 org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) 在 org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:313) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) 在 org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) 在 com.github.p4535992.Application.main(Application.java:50) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java:498) 在 org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) 引起:org.springframework.boot.context.embedded.EmbeddedServletContainerException:无法启动嵌入式Tomcat 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:116) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:83) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:530) 在 com.github.p4535992.Application$1.getTomcatEmbeddedServletContainer(Application.java:101) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:176) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ...省略了13个常用框架 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardServer[-1]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 在 org.apache.catalina.startup.Tomcat.start(Tomcat.java:356) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97) ...省略了19个常用框架 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardService[Tomcat]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 在 org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ...省略了21个常用框架 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardEngine[Tomcat]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) 在 org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ...省略了23个常用框架 原因:org.apache.catalina.LifecycleException:子容器在启动期间失败 在 org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) 在 org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ... 省略了 25 个常用帧
有什么建议吗?
在 M. Deinum 评论后更新问题:23-08-2016
【问题讨论】:
不要混用tomcat版本。您正在混合7.0.59
和9.0.0.M9
。切勿混合框架、库的版本。
【参考方案1】:
不确定您现在是否已解决。 大多数类似的问题是由于依赖项中的 tomcat jar 文件版本不正确。
我今天遇到了类似的问题,我做了什么来解决它:
-
在“IntelliJ IDEA”maven项目窗口中,有一个“Show Dependencis”按钮,点击。
搜索“servlet”,找出所有未执行的servlet jar,排除它们。
pom.xml 将自动添加以下行
<exclusions>
<exclusion>
<artifactId>servlet-api-2.5</artifactId>
<groupId>org.mortbay.jetty</groupId>
</exclusion>
</exclusions>
您也可以mvn dependency:tree
获取列表并找出不正确的 tomcat 依赖项。使用 IDE 会更快。
【讨论】:
以上是关于无法启动嵌入式容器 Spring Boot Application org.apache.catalina.LifecycleException:子容器在启动期间失败的主要内容,如果未能解决你的问题,请参考以下文章
无法在 Eclipse 中启动 Spring Boot App:无法启动嵌入式 Tomcat
无法启动 bean 'webServerStartStop';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web