如何在Spring Boot的嵌入式tomcat中扩展战争? [英] How to expand war in Spring Boot's embedded tomcat?

查看:146
本文介绍了如何在Spring Boot的嵌入式tomcat中扩展战争?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有Web应用程序的战争档案.我想在我的Spring Boot应用程序中启动该应用程序.因此,我遵循了的建议:

I have a war archive with a web application. I want to start that application within my Spring Boot application. I therefore followed the advice from that question:

@Bean
public EmbeddedServletContainerFactory servletContainerFactory() {
    return new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
            try {
                tomcat.addWebapp("blog", "/tmp/roller.war");

            } catch (ServletException ex) {
                throw new IllegalStateException("Failed to add webapp", ex);
            }
            return super.getTomcatEmbeddedServletContainer(tomcat);
        }

    };
}

这很好,除了战争没有被提取:

That works quite well, except the war doesn't get extracted:

无法创建目录[/tmp/tomcat.9153500015669016883.8080/webapps/blog]

Unable to create the directory [/tmp/tomcat.9153500015669016883.8080/webapps/blog]

这是tomcat工作目录的布局:

That's the layout of the tomcat working directory:

$ find /tmp/tomcat.9153500015669016883.8080/
/tmp/tomcat.9153500015669016883.8080/
/tmp/tomcat.9153500015669016883.8080/work
/tmp/tomcat.9153500015669016883.8080/work/Tomcat
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost/blog
/tmp/tomcat.9153500015669016883.8080/work/Tomcat/localhost/ROOT

A 断点位于ExpandWar.expand() 表示希望在webapps/中创建目录.此不存在的webapps文件夹来自Host.getAppBaseFile()(来自ContextConfig.context).

所以对我来说,似乎配置有些奇怪,应该将其扩展到work/Tomcat/localhost/blog中.我该怎么办?

So for me it looks like something is weird configured and it should be expanded into work/Tomcat/localhost/blog. How can I do that?

推荐答案

似乎这与春季无关,但是嵌入式tomcat的预期行为.我发现此相关问题:

It seems that this is not spring related, but expected behaviour of an embedded tomcat. I found this related issue:

要求用户为主机的appBase定义有效目录.

The user is expected to define a valid directory for a Host's appBase.

因此,只需在部署之前创建默认的appBase目录即可:

So simply creating the default appBase directory before deployment does the trick:

tomcat.getHost().getAppBaseFile().mkdir();
tomcat.addWebapp("blog", "/tmp/roller.war");

这篇关于如何在Spring Boot的嵌入式tomcat中扩展战争?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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