【问题标题】:How to expand war in Spring Boot's embedded tomcat?如何在 Spring Boot 嵌入式 tomcat 中展开战争?
【发布时间】:2016-10-11 01:37:12
【问题描述】:

我有一个带有 Web 应用程序的战争档案。我想在我的 Spring Boot 应用程序中启动该应用程序。因此我听从了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);
        }

    };
}

效果很好,只是战争没有被提取出来:

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

这就是tomcat工作目录的布局:

$ 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

breakpoint in ExpandWar.expand() 透露它想在 webapps/ 中创建一个目录。这个不存在的 webapps 文件夹取自 Host.getAppBaseFile()(来自 ContextConfig.context)。

所以对我来说,似乎有些东西配置得很奇怪,应该将其扩展为 work/Tomcat/localhost/blog。我该怎么做?

【问题讨论】:

    标签: spring tomcat spring-boot war


    【解决方案1】:

    这似乎与弹簧无关,而是嵌入式 tomcat 的预期行为。我找到了this related issue

    用户应该为主机的 appBase 定义一个有效的目录。

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

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

    【讨论】:

      猜你喜欢
      • 2019-09-30
      • 2015-10-28
      • 1970-01-01
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 2013-11-23
      • 2018-11-03
      相关资源
      最近更新 更多