构建单个Spring Boot WAR项目以进行部署 [英] Build single Spring Boot WAR project for deployment

查看:220
本文介绍了构建单个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.

In project-A I have defined the data model. Project-B is a Spring Boot project where I define operations for consuming rest API calls with RestTemplate. Project-C is also a Spring Boot project where I am exposing some REST services. The second project (B) requires the dependency for the first project (A). The third project (C) requires the dependencies for the first and second project (A, B). I have defined these dependencies in the respective projects (B, C) pom files. All three projects have pom packaging type.

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

Now I want to create a single Spring Boot WAR project for deployment on a tomcat server. My purpose is to have this single WAR that encapsulates all other projects (A, B, C). So I want to be able to make my rest services (project-C) accessible through this single WAR.

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

I tried creating a Spring Boot project with packaging type war and added the dependency for project-C (which includes the dependencies for project-A and project-B), but I am not able to deploy the generated WAR file because of a:

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)

有没有一种方法可以处理这种方法?

Is there a way how can I handle this approach?

推荐答案

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

You have to package your Spring-Boot project as a war in your pom and exclude the spring-boot-starter-tomcat dependency in the spring-boot-starter-web dependency.

<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-Services项目(在您的情况下为Project-C)中执行此操作.

You have to do this on your REST-Services project, which is Project-C in your case.

这篇关于构建单个Spring Boot WAR项目以进行部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆