繁体   English   中英

Spring Boot嵌入式Tomcat'allowLinking'属性

[英]Spring Boot Embedded Tomcat 'allowLinking' property

我一直在寻找一种方法来公开属性'allowLinking',以允许TomcatEmbeddedServletContainerFactory遵循符号链接到其documentRoot下的资源。

根据Tomcat 8 Migration文档,此功能切换到Tomcat 8+的“Resources”标签: Tomcat 8迁移指南

<!-- Tomcat 7: -->
<Context allowLinking="true" />

<!-- Tomcat 8: -->
<Context>
  <Resources allowLinking="true" />
</Context>

如何以编程方式为Spring Boot应用程序配置TomcatEmbeddedServletContainerFactory时如何公开此属性?

我有完全相同的问题,并能够实现以下解决此问题:

@Bean
public EmbeddedServletContainerFactory servletContainer() 
{
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    // allow symbolic links under the filesystem context
    // don't use this on Windows!
    if (IOCase.SYSTEM.isCaseSensitive())
    {
        Log.info("Enabling support for symbolic links on the webserver.");
        for (TomcatContextCustomizer customizer : tomcat.getTomcatContextCustomizers())
        {
            StandardContext context = new StandardContext();
            context.setAllowLinking(true);
            customizer.customize(context);
        }
    }
    return tomcat;
}

在Tomcat 8中修改代码的Erik Brandsberg解决了这个问题

@Bean
public EmbeddedServletContainerFactory servletContainer()
{
    TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
    // allow symbolic links under the filesystem context
    // don't use this on Windows!
    if (IOCase.SYSTEM.isCaseSensitive())
    {
        TomcatContextCustomizer customizer = new TomcatContextCustomizer() {
            @Override
            public void customize(Context context) {
                StandardRoot r = new StandardRoot();
                r.setAllowLinking(true);
                context.setResources(r);
            }
        };
        tomcat.addContextCustomizers(customizer);

    }
    return tomcat;
}

暂无
暂无

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

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