我有一個spring bean,它有一個記錄器成員,我使用該記錄器記錄一些操作。
另外我寫了一個使用SpringJUnit4ClassRunner
的測試用例。我有一個屬性文件配置Log4j和在每個測試情況下,我初始化這些屬性的記錄:JUnit中的Log4j測試用例
@BeforeClass
public static void init() {
PropertyConfigurator.configure("src/com/config/log4j.properties");
}
當我運行一個測試它給了我一個警告
log4j:WARN No appenders could be found for logger (org.springframework.test.context.junit4.SpringJUnit4ClassRunner).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
然而,在記錄器我的bean將消息寫入log4j.properties中的指定位置,即它可以正常工作。 爲什麼log4j會給我這樣的警告?
作爲出路,您可以將'-Dlog4j.configuration = com/config/log4j.properties'傳遞給JVM。您提到的代碼可以被刪除。 –