2016-01-06 129 views
2

我一直在尋找一種方法來公開'allowLinking'屬性,以允許TomcatEmbeddedServletContainerFactory遵循符號鏈接到其documentRoot下的資源。Spring Boot嵌入式Tomcat'allowLinking'屬性

據Tomcat的8遷移文檔此功能切換到「資源」標籤爲Tomcat 8+:Tomcat 8 Migration Guide

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

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

而編程配置TomcatEmbeddedServletContainerFactory的春天啓動應用程序如何將一個揭露這個屬性?

回答

0

我有完全一樣的問題,而且是能夠實現以下以解決此問題:

@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; 
} 
0

THKS埃裏克Brandsberg,修改代碼,在Tomcat中8來解決這個問題

@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; 
} 
相關問題