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();

注意:Ifyouchoosetocalloneofthesemethods,youshoulddosobeforecallinganyotherMyBatis

method.Also,thesemethodswillonlyswitchtotherequestedlogimplementationifthat

implementationisavailableontheruntimeclasspath.Forexample,ifyoutrytoselectLog4Jlogging

andLog4Jisnotavailableatruntime,thenMyBatiswillignoretherequesttouseLog4Jandwilluse

it'snormalalgorithmfordiscoveringloggingimplementations.

针对红色的那段字。我使用的是spring,在spring启动的时候调用LogFactory.useLog4JLogging();打印成功