前言

  • 默认日志类:org.apache.ibatis.logging.stdout.StdOutImpl

方法一

  • MyBatis
mybatis.configuration.log-impl=org.apache.ibatis.logging.nologging.NoLoggingImpl
  • MyBatis-Plus
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl

方法二

@Bean
public SqlSessionFactory sqlSessionFactory() throws Exception {
// 用 mybatis 的这里会有点区别, mybatis 用的是 SqlSessionFactoryBean
MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dynamicDataSource());
sqlSessionFactoryBean.setMapperLocations((new PathMatchingResourcePatternResolver()).getResources("classpath:mapper/*.xml"));

// 关闭日志
MybatisConfiguration configuration = new MybatisConfiguration();
configuration.setLogImpl(NoLoggingImpl.class);
sqlSessionFactoryBean.setConfiguration(configuration);

return sqlSessionFactoryBean.getObject();
}