log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).

一、异常描述:

  1 log4j:WARN No appenders could be found for logger
  2 (org.springframework.web.context.ContextLoader).
  3 log4j:WARN Please initialize the log4j system properly.
  4 log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

二、错误分析:缺少日志文件。

三、解决方法:在src/main/resources上面右键 New—>File,File name: log4j.properties。

文件内容如下:

  1 # Configure logging for testing: optionally with log file
  2 log4j.rootLogger=WARN, stdout
  3 # log4j.rootLogger=WARN, stdout, logfile
  4 
  5 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  6 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  7 log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
  8 
  9 log4j.appender.logfile=org.apache.log4j.FileAppender
 10 log4j.appender.logfile.File=target/spring.log
 11 log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
 12 log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

完整配置如下:

  1 log4j.rootLogger=CONSOLE,FILE
  2 log4j.addivity.org.apache=true
  3 
  4 # 应用于控制台
  5 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
  6 log4j.appender.CONSOLE.Threshold=INFO
  7 log4j.appender.CONSOLE.Target=System.out
  8 log4j.appender.CONSOLE.Encoding=GBK
  9 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
 10 log4j.appender.CONSOLE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
 11 
 12 # 每天新建日志
 13 log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
 14 log4j.appender.A1.File=C:/log4j/log
 15 log4j.appender.A1.Encoding=GBK
 16 log4j.appender.A1.Threshold=DEBUG
 17 log4j.appender.A1.DatePattern='.'yyyy-MM-dd
 18 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
 19 log4j.appender.A1.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L : %m%n
 20 
 21 #应用于文件
 22 log4j.appender.FILE=org.apache.log4j.FileAppender
 23 log4j.appender.FILE.File=C:/log4j/file.log
 24 log4j.appender.FILE.Append=false
 25 log4j.appender.FILE.Encoding=GBK
 26 log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
 27 log4j.appender.FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
 28 
 29 # 应用于文件回滚
 30 log4j.appender.ROLLING_FILE=org.apache.log4j.RollingFileAppender
 31 log4j.appender.ROLLING_FILE.Threshold=ERROR
 32 log4j.appender.ROLLING_FILE.File=rolling.log
 33 log4j.appender.ROLLING_FILE.Append=true
 34 log4j.appender.CONSOLE_FILE.Encoding=GBK
 35 log4j.appender.ROLLING_FILE.MaxFileSize=10KB
 36 log4j.appender.ROLLING_FILE.MaxBackupIndex=1
 37 log4j.appender.ROLLING_FILE.layout=org.apache.log4j.PatternLayout
 38 log4j.appender.ROLLING_FILE.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
 39 
 40 #自定义Appender
 41 log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender
 42 log4j.appender.im.host = mail.cybercorlin.net
 43 log4j.appender.im.username = username
 44 log4j.appender.im.password = password
 45 log4j.appender.im.recipient = yyflyons@163.com
 46 log4j.appender.im.layout=org.apache.log4j.PatternLayout
 47 log4j.appender.im.layout.ConversionPattern =[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n
 48 
 49 #应用于socket
 50 log4j.appender.SOCKET=org.apache.log4j.RollingFileAppender
 51 log4j.appender.SOCKET.RemoteHost=localhost
 52 log4j.appender.SOCKET.Port=5001
 53 log4j.appender.SOCKET.LocationInfo=true
 54 # Set up for Log Facter 5
 55 log4j.appender.SOCKET.layout=org.apache.log4j.PatternLayout
 56 log4j.appender.SOCET.layout.ConversionPattern=[start]%d{DATE}[DATE]%n%p[PRIORITY]%n%x[NDC]%n%t[THREAD]%n%
 57 c[CATEGORY]%n%m[MESSAGE]%n%n
 58 # Log Factor 5 Appender
 59 log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender
 60 log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000
 61 
 62 # 发送日志给邮件
 63 log4j.appender.MAIL=org.apache.log4j.net.SMTPAppender
 64 log4j.appender.MAIL.Threshold=FATAL
 65 log4j.appender.MAIL.BufferSize=10
 66 log4j.appender.MAIL.From=yyflyons@163.com
 67 log4j.appender.MAIL.SMTPHost=www.wusetu.com
 68 log4j.appender.MAIL.Subject=Log4J Message
 69 log4j.appender.MAIL.To=yyflyons@126.com
 70 log4j.appender.MAIL.layout=org.apache.log4j.PatternLayout
 71 log4j.appender.MAIL.layout.ConversionPattern=[framework] %d - %c -%-4r [%t] %-5p %c %x - %m%n

 

问题补充:

若加入 log4j.properties 日志文件后,警告信息变成了如下内容:

  1 2017-10-13 18:22:27,018 WARN [org.hibernate.util.DTDEntityResolver] - recognized obsolete
  2 hibernate namespace http://hibernate.sourceforge.net/. Use namespace 
  3 http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  4 2017-10-13 18:22:27,044 WARN [org.hibernate.util.DTDEntityResolver] - recognized obsolete
  5 hibernate namespace http://hibernate.sourceforge.net/. Use namespace 
  6 http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
  7 2017-10-13 18:22:27,651 WARN [org.hibernate.util.DTDEntityResolver] - recognized obsolete
  8 hibernate namespace http://hibernate.sourceforge.net/. Use namespace 
  9 http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!

针对警告 WARN [org.hibernate.util.DTDEntityResolver] - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! 解决方法:

1、检查所有***.hbm.xml文件,看看是不是有
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"
更改为
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"

2、检查hibernate.cfg.xml文件,将
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"
更改为
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"

posted @ 2017-10-13 18:36  长情白月光  阅读(1140)  评论(0编辑  收藏  举报