mytatis打印SQL语句

来源:互联网 发布:达内培训 java测试 编辑:程序博客网 时间:2024/06/04 17:53
mybatis默认使用log4j,当有self4j这个日志jar包存在时会无法打印sql,请移除或者在工程启动时显示设置mybatis使用的日志类
log4j.logger.org.apache.ibatis=debug,stdout
log4j.logger.java.sql=debug,stdout


---------------------------------------------------------------
今天又碰到按照上面那样做了还是没有打印sql,原因在于不可能移除self4j包,因为其他依赖包必须依赖这个包,。。。。不得已又去查资料。
mybatis有如下方法来手动选择日志类,调用后成功打印日志
org.apache.ibatis.logging.LogFactory.useSlf4jLogging();
org.apache.ibatis.logging.LogFactory.useLog4JLogging();
org.apache.ibatis.logging.LogFactory.useJdkLogging();
org.apache.ibatis.logging.LogFactory.useCommonsLogging();
org.apache.ibatis.logging.LogFactory.useStdOutLogging();

注意:If you choose to call one of these methods, you should do so before calling any other MyBatis
method.
Also, these methods will only switch to the requested log implementation if that
implementation is available on the runtime classpath. For example, if you try to select Log4J logging
and Log4J is not available at runtime, then MyBatis will ignore the request to use Log4J and will use
it's normal algorithm for discovering logging implementations.

针对红色的那段字。我使用的是spring,在spring启动的时候调用LogFactory.useLog4JLogging();打印成功
 
本文转自http://13146489.iteye.com/blog/1037512

http://mybatis.github.io/mybatis-3/zh/logging.html