2017-03-29 7 views
3

STSから私は標準のSpring Boot 1.5.2 'Web'プロジェクトを作成しています。私はWARプロジェクトにこのプロジェクトを変更した場合、私は唯一の「ベース」ディレクトリ/tmp/tomcat-docbaseは常にSpringブートJAR(WARではなく)で作成されます

を取得し、通常の「ベース」ディレクトリと「Tomcatの-文書ベース」ディレクトリ

. . . 4096 Mar 29 10:00 tomcat.2743776473678691880.8080 
. . . 4096 Mar 29 10:00 tomcat-docbase.76291847886629412.8080 

- あなたはこのアプリケーションを実行する場合は、作成した2つのディレクトリを取得します

. . . 4096 Mar 29 10:06 tomcat.3131223012454570991.8080 

それは

server.tomcat.basedir=. 

を使用して、デフォルトのベースディレクトリを上書きするのは簡単ですが、これはTomcatの-文書ベースには影響しません。 tomcat-docbaseをプログラムでオーバーライドすることは可能ですが、ハックのように見えます。

これはバグだと思いますか?

おかげ

答えて

0

ソリューション: あなたのJARと同じフォルダに、あなたのプロジェクトの下公共としてフォルダ名を作成します。

理由: springbootコードから、docbaseフォルダの設定はありません。 しかし、あなたは公共静的またはのsrc /メイン/ webappのとして、あなたのプロジェクトのフォルダ名に共通のルートフォルダを作成することができ、その後、springbootは再びあなたのための一時のtomcat-文書ベースのフォルダを作成することはありません。

private static final String[] COMMON_DOC_ROOTS = { "src/main/webapp", "public", "static" } 
... 
public final File getValidDirectory() { 
    File file = this.directory; 
    file = (file != null ? file : getWarFileDocumentRoot()); 
    file = (file != null ? file : getExplodedWarFileDocumentRoot()); 
    file = (file != null ? file : getCommonDocumentRoot()); 
    if (file == null && this.logger.isDebugEnabled()) { 
     logNoDocumentRoots(); 
    } 
    else if (this.logger.isDebugEnabled()) { 
     this.logger.debug("Document root: " + file); 
    } 
    return file; 
} 
... 
private File getCommonDocumentRoot() { 
    for (String commonDocRoot : COMMON_DOC_ROOTS) { 
     File root = new File(commonDocRoot); 
     if (root.exists() && root.isDirectory()) { 
      return root.getAbsoluteFile(); 
     } 
    } 
    return null; 
} 

リンク:DocumentRoot.java

0

私は春と組み込みTomcatサーバーで文書ベースのフォルダを設定するプログラムでの方法を見つけました。

public @Bean EmbeddedServletContainerFactory embeddedServletContainerFactory() { 
    TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory("/app", 8080) { 
     @Override 
     protected void configureContext(Context context, ServletContextInitializer[] initializers) { 
      context.setDocBase("/path/to/your/docbase"); 
      super.configureContext(context, initializers); 
     } 
    }; 
    return factory; 
} 
のように、 TomcatEmbeddedServletContainerFactoryの実装を上書きする必要があります。