MYBATIS3.2.3+SPRING3 Console Print SQL solution

Source: Internet
Author: User
Tags log4j

Learn MyBatis When you encounter the problem of printing SQL, here is a summary:

1: First log4j.properties such a configuration;

Log4j.rootlogger=Debug,console,rlog4j.appender.console=Org.apache.log4j.ConsoleAppenderlog4j.appender.console.threshold=Debuglog4j.appender.console.layout=Org.apache.log4j.PatternLayoutlog4j.appender.console.layout.ConversionPattern=%d{yyyy-mm-dd HH:MM:SS} [%5p]-%c-%m (%l)-%m%NLOG4J.APPENDER.R=Org.apache.log4j.rollingfileappenderlog4j.appender.r.append=trueLog4j.appender.r.file=d:/Springmvc.loglog4j.appender.r.threshold=Warnlog4j.appender.r.layout=Org.apache.log4j.patternlayoutlog4j.appender.r.layout.conversionpattern=%d{yyyy-mm-dd HH:MM:SS} [%5p]-%c-%m (%l)-%m%nlog4j.appender.r.maxfilesize=20mb# Avoid debug level log input log4j.logger.org= info

2: Check your own imported jar package to see if there are three packages log4j Slf4j-api SLF4J-LOG4J12

If the three packages are present or there is only log4j, skip step 3

3: Project to SLF4J-API and do not want to import slf4j-log12, then make the following configuration:

Spring Configuration:<BeanID= "Sqlsessionfactory"class= "Org.mybatis.spring.SqlSessionFactoryBean">           < Propertyname= "DataSource"ref= "DataSource"/>           < Propertyname= "Mapperlocations"value= "Classpath:com/chencheng/mapping/*.xml"/>           <!--Register MyBatis Profile--! > <property name= "configlocation" value= "Classpath:mybatis-config.xml"/> &L t;/bean> mybatis-config.xml Configuration <?xml version= "1.0" encoding= "UTF-8"? ><! DOCTYPE configuration Public "-//mybatis.org//dtd Config 3.0//en" "Http://mybatis.org/dtd/mybatis-3-config.dtd" > <configuration> <settings> <setting name= "Logimpl" value= "log4j"/>//Use log4j </settings& Gt;</configuration>

To complete the above configuration, we should be able to see the SQL printed on the console.

MYBATIS3.2.3+SPRING3 Console Print SQL solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.