构建单个Spring Boot WAR项目以进行部署

时间:2017-02-22 14:41:24

标签: java spring maven spring-boot war

我有三个项目:

project-A
project-B 
project-C

project-A我定义了数据模型。 Project-B是一个Spring Boot项目,我在其中定义了使用RestTemplate来消耗其余API调用的操作。 Project-C也是一个Spring Boot项目,我公开了一些REST服务。 第二个项目(B)需要第一个项目(A)的依赖项。第三个项目(C)需要第一个和第二个项目(A,B)的依赖项。我已在相应的项目(B,C)pom文件中定义了这些依赖项。 这三个项目都有pom包装类型。

现在我想创建一个Spring Boot WAR项目,以便在tomcat服务器上进行部署。我的目的是让这个单独的WAR封装所有其他项目(A,B,C)。所以我希望能够通过这个单一的WAR访问我的休息服务(project-C)。

我尝试创建一个包装类型为war的Spring Boot项目,并添加了project-C的依赖项(包括project-Aproject-B的依赖项),但我是由于以下原因无法部署生成的WAR文件:

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[/mywarproject-war-0.0.1-SNAPSHOT]]
        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@af7b84d]
        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@517f5687]
        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: error in opening zip file
        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: error in opening zip file
        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)

有什么方法可以处理这种方法?

1 个答案:

答案 0 :(得分:1)

您必须将Spring-Boot项目打包为pom中的war,并在spring-boot-starter-web依赖项中排除spring-boot-starter-tomcat依赖项。

<packaging>war</packaging>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

您必须在REST服务项目中执行此操作,在您的情况下,这是Project-C.