我一直在寻找一种方法来公开属性'allowLinking',以允许TomcatEmbeddedServletContainerFactory遵循符号链接到其documentRoot下的资源。
根据Tomcat 8 Migration文档,此功能已切换为Tomcat 8+的“Resources”标记:Tomcat 8 Migration Guide
<!-- Tomcat 7: -->
<Context allowLinking="true" />
<!-- Tomcat 8: -->
<Context>
<Resources allowLinking="true" />
</Context>
如何以编程方式为Spring Boot应用程序配置TomcatEmbeddedServletContainerFactory时如何公开此属性?
答案 0 :(得分:2)
我有完全相同的问题,并且能够实现以下解决方法:
@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;
}
答案 1 :(得分:1)
@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;
}