增加日志功能方便调试程序,log4j.properties文件如下(放到工程src根目录下)
# This is the configuring for logging displayed in the Application Server
log4j.rootCategory=INFO, stdout
# Replace the line above if you want to put a log file into the directory
# you start Tomcat from
# log4j.rootCategory=INFO, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=\u5de5\u7a0b\u53c2\u6570\uff1a %p [%t] %C{1}.%M(%L) | %m%n
log4j.appender.R=org.apache.log4j.RollingFileAppender
# You can change this to be an absolute path or even an environment variable
# If you're using an environment variable, you will have to set JAVA_OPTS
# to contain this variables - for example in the catalina.sh or catalina
# file
log4j.appender.R.File=@[email protected]
log4j.appender.R.MaxFileSize=100KB
# Don't keep a backup file
log4j.appender.R.MaxBackupIndex=0
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
# Configuration for receiving e-mails when ERROR messages occur.
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.To=@ERROR-MAILTO@
log4j.appender.mail.From=@ERROR-SERVER@@raibledesigns.com
log4j.appender.mail.SMTPHost=@ERROR-MAILHOST@
log4j.appender.mail.Threshold=ERROR
log4j.appender.mail.BufferSize=1
log4j.appender.mail.Subject=[@ERROR-SERVER@] @APPNAME@ Application Error
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d %-5p %c %x - %m%n
# If programmed properly the most messages would be at DEBUG
# and the least at FATAL.
log4j.logger.org.appfuse=DEBUG
log4j.logger.org.appfuse.webapp.filter=ERROR
log4j.logger.org.appfuse.webapp.listener.UserCounterListener=WARN
log4j.logger.org.appfuse.util=WARN
# Control logging for other open source packages
log4j.logger.com.opensymphony.oscache=ERROR
log4j.logger.net.sf.navigator=ERROR
log4j.logger.org.apache.commons=ERROR
log4j.logger.org.apache.struts=WARN
log4j.logger.org.displaytag=ERROR
log4j.logger.org.springframework=WARN
log4j.logger.com.ibatis.db=WARN
log4j.logger.org.apache.velocity=FATAL
# Don't show debug logs for WebTest
log4j.logger.com.canoo.webtest=WARN
# All hibernate log output of "info" level or higher goes to stdout.
# For more verbose logging, change the "info" to "debug" on the last line.
log4j.logger.net.sf.hibernate.ps.PreparedStatementCache=WARN
log4j.logger.net.sf.hibernate=WARN
log4j.logger.cn.com.hebnews.seven.util.autorun=all
注意: Add Struts Capabilities时并没有加入log4j.jar包,为了提供log4j功能,需要加上log4j.jar。
这里是因为导入Spring的时候附带导入了log4j.jar包,所以此处不用再另外导入log4j.jar包
3.6. 测试
同上一次测试。测试成功证明 Spring 运行正常。