gpt4 book ai didi

java - 无法启动嵌入式容器 Spring Boot 应用程序 org.apache.catalina.LifecycleException : A child container failed during start

转载 作者:行者123 更新时间:2023-11-28 22:01:40 30 4
gpt4 key购买 nike

尝试使用 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'
}
}

应用程序.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);
}
}

CacheConfiguratrion.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();
}
}

...当我尝试在应用程序上运行程序时,我在代码段中得到以下异常 return super.getTomcatEmbeddedServletContainer(tomcat);:

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) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:535) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:369) at org.springframework.boot.SpringApplication.run(SpringApplication.java:313) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) at com.github.p4535992.Application.main(Application.java:50) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:116) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.(TomcatEmbeddedServletContainer.java:83) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:530) at com.github.p4535992.Application$1.getTomcatEmbeddedServletContainer(Application.java:101) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:176) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ... 13 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:356) at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:97) ... 19 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ... 21 common frames omitted Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:158) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ... 23 common frames omitted Caused by: org.apache.catalina.LifecycleException: A child container failed during start at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152) ... 25 common frames omitted

有什么建议吗?

在 M. Deinum 评论后更新问题:23-08-2016

最佳答案

不确定您现在是否解决了。类似的问题主要是由于依赖项中的 tomcat jar 文件版本不正确。

我今天遇到了类似的问题,我是如何解决的:

  1. 在“IntelliJ IDEA”maven 项目窗口中,有一个按钮“Show Dependencis”,点击它。
  2. 搜索“servlet”,找出所有未执行的servlet jar,排除它们。
  3. pom.xml 将自动添加以下行

    <exclusions>
    <exclusion>
    <artifactId>servlet-api-2.5</artifactId>
    <groupId>org.mortbay.jetty</groupId>
    </exclusion>
    </exclusions>

您还可以mvn dependency:tree 获取列表并找出不正确的tomcat 依赖项。使用 IDE 会更快。

关于java - 无法启动嵌入式容器 Spring Boot 应用程序 org.apache.catalina.LifecycleException : A child container failed during start,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39079888/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com