简体   繁体   English

部署示例Spring Boot应用程序时的生命周期异常

[英]Lifecycle exception when deploying example spring boot app

I am trying to understand the basic steps of how to deploy a spring boot application. 我正在尝试了解如何部署Spring Boot应用程序的基本步骤。 However, despite the fact that I do everything correctly, I can't deploy it on a tomcat server. 但是,尽管我可以正确执行所有操作,但是我无法将其部署在tomcat服务器上。 The tomcat successfuly extracts my war archive but it gives the folloving below error: tomcat成功提取了我的war档案,但出现了以下错误:

11-Dec-2016 16:49:31.975 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
 org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springrest]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.webresources.StandardRoot@5a0050e9]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
    at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4842)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4974)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 10 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.JarResourceSet@57a81b37]
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
    at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:708)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    ... 13 more
Caused by: java.lang.IllegalArgumentException: java.util.zip.ZipException: invalid END header (bad central directory offset)
    at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:113)
    at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
    ... 16 more
Caused by: java.util.zip.ZipException: invalid END header (bad central directory offset)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(ZipFile.java:219)
    at java.util.zip.ZipFile.<init>(ZipFile.java:149)
    at java.util.jar.JarFile.<init>(JarFile.java:166)
    at java.util.jar.JarFile.<init>(JarFile.java:103)
    at org.apache.catalina.webresources.AbstractSingleArchiveResourceSet.initInternal(AbstractSingleArchiveResourceSet.java:110)
    ... 17 more

11-Dec-2016 16:49:31.976 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /home/bora/Desktop/apache-tomcat-8.5.9/webapps/springrest.war
 java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/springrest]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I think the error is caused by a ZipException. 我认为该错误是由ZipException引起的。 But I don't understand why. 但是我不明白为什么。 I have followed this and this guides as exactly as it written, but ... 我已经按照指南和指南的要求进行了严格的编写,但是...

Here is more files, maybe it will be useful: pom.xml: 这是更多文件,可能会有用:pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.bora.test</groupId>
    <artifactId>springrest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <!-- <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> -->

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

</project>

And my Application class: package com.bora.rest; 我的应用程序类:com.bora.rest包;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;

@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application extends SpringBootServletInitializer {

    private static Class<Application> applicationClass = Application.class;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        // TODO Auto-generated method stub
        return builder.sources(Application.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

class GreetingController {

    @RequestMapping("/")
    String hello() {
        return "Hello World";
    }

}

I compile and package my maven project by givin mvn clean package and coppy the .war file into my tomcat's webapps folder. 我通过givin mvn clean package编译并打包我的maven项目,并将.war文件复制到tomcat的webapps文件夹中。 Restart the tomcat, it extracts but the above error occurs. 重新启动tomcat,它将提取但出现上述错误。 I have been searching for solution for about 2 hours, but ... 我一直在寻找解决方案大约2个小时,但是...

My tomcat version is 8.5.9. 我的tomcat版本是8.5.9。 I am using Ubuntu 16.04. 我正在使用Ubuntu 16.04。 Environment variables: 环境变量:

$CATALINA_BASE: /home/bora/Desktop/apache-tomcat-8.5.9
$CATALINA_HOME: /home/bora/Desktop/apache-tomcat-8.5.9
$CATALINA_TMPDIR: /home/bora/Desktop/apache-tomcat-8.5.9/temp
$JRE_HOME:        /home/bora/Applications/jdk1.8.0_111
$CLASSPATH:       /home/bora/Desktop/apache-tomcat-8.5.9/bin/bootstrap.jar:/home/bora/Desktop/apache-tomcat-8.5.9/bin/tomcat-juli.jar

I have strong knowledge about java language, I develop android applications. 我对Java语言有很深的了解,我开发android应用程序。 However, I am totally stranger to Java EE technologies. 但是,我对Java EE技术完全陌生。 If someone finds an answer, could you please tell me the answer like you telling a child? 如果有人找到答案,能否像告诉孩子一样请告诉我答案?

Thank you very much. 非常感谢你。

Spring-Boot ist using Tomcat 7 as default. Spring-Boot ist默认使用Tomcat 7。 This should be the reason why you get an exception. 这应该是您获得例外的原因。 If u want to use Tomcat 8.5.9 u have to set the Version in your pom.xml: 如果要使用Tomcat 8.5.9,则必须在pom.xml中设置版本:

<properties>
    <tomcat.version>8.5.9</tomcat.version>
</properties>

EDIT 编辑

Use the spring-boot-maven-plugin for building the app. 使用spring-boot-maven-plugin构建应用程序。 So you cant be sure your app is builded correctly. 因此,您不能确定您的应用程序构建正确。

EDIT 2 编辑2

Just annotate your class with @SpringBootApplication this is enough. 只需使用@SpringBootApplication注释您的类就足够了。 your Dont need the other ones. 您不需要其他。

EDIT 3 编辑3

After compiling your code with my mentioned changes it worket fine. 用我提到的更改编译代码后,它可以正常工作。 So the issue must be your config. 因此,问题必须出在您的配置上。 Clear your local maven-repository and redownload the libaries. 清除本地Maven存储库,然后重新下载这些库。 That should work. 那应该工作。

It seems the version conflict, please check compiled version and JVM of Tomcat version are same. 似乎版本冲突,请检查编译版本和Tomcat版本的JVM是否相同。

  1. Pls check JAVA_HOME 请检查JAVA_HOME
  2. Check the Tomcat version to build. 检查要构建的Tomcat版本。 Follow the link: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html 请点击以下链接: https : //docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-servlet-containers.html

  3. Check the Java version to build: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html 检查要构建的Java版本: http : //docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html

Hope this help. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM