Spring + log4j構成ファイルがシステム環境変数の問題を読み取れません
Spring Log4j Configuration File Cant Read System Environment Variable Problem
spring-webプロジェクトでは、log4j構成はlog4j.propertiesファイルにあり、ログパスは環境変数(/ etc / profileで構成)を使用して構成されます。ただし、パスの実際の実行は有効になりません。パスを直接記述すれば問題ありません。
log4j.appender.logFile.File = ${BYTREES_LOG4J_FILE}
原因分析:
Log4jはSystem.getPropertyを使用してシステムプロパティを読み取り、System.getenvは環境変数を読み取ります。 org.apache.log4j.helpers.OptionConverterを参照してください
解決:
春が始まる前に環境変数をシステムプロパティに変換するリスナーを作成します。
作成されたリスナー:
package com.bytrees.utils import javax.servlet.ServletContextEvent import javax.servlet.ServletContextListener public class PropertiesListener implements ServletContextListener { @Override public void contextInitialized(ServletContextEvent sce) { // TODO Auto-generated method stub String log4jLogFile = System.getenv('BYTREES_LOG4J_FILE') if (log4jLogFile != null) { System.setProperty('BYTREES_LOG4J_FILE', log4jLogFile) } } @Override public void contextDestroyed(ServletContextEvent sce) { // TODO Auto-generated method stub System.getProperties().remove('BYTREES_LOG4J_FILE') } }
web.xmlを構成します。これは、ContextLoaderListenerの前にある必要があることに注意してください。
com.bytrees.utils.PropertiesListener