SSM框架下,启动服务器后控制台显示
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
程序能正常运行,但不显示Mybatis中执行的SQL语句,不方便调试。解决办法:
第一步:在mybatis-config.xml中加入
<configuration>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
</configuration>
第二步:src下加入文件log4j.properties
# Global logging configuration
log4j.rootLogger=ERROR, stdout
# MyBatis logging configuration...
log4j.logger.com.dao=DEBUG
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
log4j.logger.com.dao=DEBUG中:com.dao表示映射器包,后边可继续跟上接口名;DEBUG表示在控制台显示执行的SQL语句,若把DEBUG换成TRACE则表示在控制台显示执行的SQL语句和返回的结果集。
我就是遗漏了第一步。
参考:Mybatis解压包中的mybatis-3.5.3\mybatis-3.5.3.pdf最后一章Logging。