当前位置: 首页 > 知识库问答 >
问题:

无法启动嵌入式容器Spring Boot应用程序org.apache.catalina.LifeCycleException:启动时子容器失败

元玮
2023-03-14
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'
    }
}
@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);
}
}
Configuration
@EnableCaching
@Profile("!nocache")
public class CacheConfiguration {}
@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();
}
}

有什么建议吗?

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

共有1个答案

孟璞
2023-03-14

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

我今天遇到了类似的问题,我做了什么来解决它:

>

  • 在“IntelliJ IDEA”maven项目窗口中,有一个按钮“显示依赖项”,请单击它。
  • 搜索“servlet”,找出所有未被删除的servlet jar,排除它们。
  • pom.xml将自动添加到行下面

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

  •  类似资料:
    • 在过去的6-7个小时里,我一直在努力找出Apache Tomcat服务器出了什么问题。在我的所有项目中,版本从切换到。 java.util.concurrent.ExecutionException:org.apache.Catalina.LifeCycleException:无法启动组件[StandardEngine[Catalina].StandardHost[localhost].Stand

    • 我是Spring的新手,所以我从Spring intializr下载了jar for maven-web java 1.8 demo。我将其提取并导入STS以运行main()文件,我得到了以下异常。有人能告诉我有什么解决方案吗? 我从Web尝试但不起作用的解决方案:-尝试将Hibernate验证器依赖项添加到pom-尝试将spring-boot-starter-tomcat依赖项添加到pom 堆栈

    • 我正在学习《行动中的Spring》第四版第5章,但是我被第一个例子困住了。 以下是我的Eclipse Luna项目结构: 如果我将此项目作为Spring Boot应用程序运行,则会引发异常: 我怎样才能解决这个问题? 所有文件的内容: 随地吐痰。爪哇: SpittrWebAppInitializer.java: 网络配置。爪哇: RootConfig。爪哇: HomeController.java

    • 我刚开始使用Spring Boot,在运行我的应用程序时出现了错误。我正在学习教程,我相信我有正确的父母和依赖与POM,请帮助我 主类: POM:

    • 我有一个Spring Boot应用程序演示,遵循以下指南https://spring.io/guides/gs/rest-service/ PS:因为启动类不在我的bean的同一个包中,所以我显式地将@componentscan添加到我的启动类中。

    • 我通过C API使用LXC,并简单地复制和粘贴了示例代码(如链接所示,但用我自己的函数名替换了)。然后从程序中的另一个代码块中调用它,我无法使容器正常启动。 调用只会返回false。如果我将第二个参数更改为start为0(意味着应该使用而不是/sbin/init),则start“成功”,但容器状态立即设置为,因此我无法连接到容器。 正在尝试通过设置获取日志: 只生成空文件。 想到这可能与我看到的另