springboot+mybatis+mysql项目
第一次连接数据库是@Transactional事务的状况
2017-10-13 11:28:00,825 [http-nio-8070-exec-1] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Creating new transaction with name [com.eversec.centertool.modules.woapi.service.WoApiService.getActivityVo]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly; ''
2017-10-13 11:29:41,342 [http-nio-8070-exec-1] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Acquired Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@5d05f6d3]]] for JDBC transaction
2017-10-13 11:29:41,347 [http-nio-8070-exec-1] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Setting JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@5d05f6d3]]] read-only
2017-10-13 11:29:41,347 [http-nio-8070-exec-1] DEBUG [org.springframework.jdbc.datasource.DataSourceTransactionManager] - Switching JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@5d05f6d3]]] to manual commit
第一次连接数据库是非@Transactional事务的状况
2017-10-13 15:03:16,202 [http-nio-8070-exec-1] DEBUG [org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
2017-10-13 15:03:16,210 [http-nio-8070-exec-1] DEBUG [org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@235030d0] was not registered for synchronization because synchronization is not active
2017-10-13 15:03:16,223 [http-nio-8070-exec-1] DEBUG [org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
2017-10-13 15:04:56,735 [http-nio-8070-exec-1] DEBUG [org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection@4aa70f74]]] will not be managed by Spring
我同事还曾经遇到从几万条数据中根据id查询用了N秒种的诡异情况,而且这种状况还是间歇性发生,最后不了了之。
我强烈建议你使用spring-data-jpa替代mybatis.
讲真mybatis的mapper的xml配置其实跟直接写jdbc毫无区别,而且jdbc更灵活直观。