Mybatis : DEBUG [main] - PooledDataSource forcefully closed/removed all connections.

本文分享了在运行MyBatis代码时遇到的日志级别问题及解决方法,详细介绍了错误的日志配置与正确的日志配置的区别,指出关键在于日志级别设置及特定的logger配置。

出现错误:

  1. DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.
  2. DEBUG [main] - Class not found: org.jboss.vfs.VFS
  3. DEBUG [main] - JBoss 6 VFS API is not available in this environment.
  4. DEBUG [main] - Class not found: org.jboss.vfs.VirtualFile
  5. DEBUG [main] - VFS implementation org.apache.ibatis.io.JBoss6VFS is not valid in this environment.
  6. DEBUG [main] - Using VFS adapter org.apache.ibatis.io.DefaultVFS
  7. DEBUG [main] - Find JAR URL: file:/D:/software%20install/chapter09/build/classes/com/company/po
  8. DEBUG [main] - Not a JAR: file:/D:/software%20install/chapter09/build/classes/com/company/po
  9. DEBUG [main] - Reader entry: idCard.class
  10. DEBUG [main] - Reader entry: Person.class
  11. DEBUG [main] - Listing file:/D:/software%20install/chapter09/build/classes/com/company/po
  12. DEBUG [main] - Find JAR URL: file:/D:/software%20install/chapter09/build/classes/com/company/po/idCard.class
  13. DEBUG [main] - Not a JAR: file:/D:/software%20install/chapter09/build/classes/com/company/po/idCard.class
    ----------------------------部分乱字符无法复制
  14. DEBUG [main] - Checking to see if class com.company.po.idCard matches criteria [is assignable to Object]
  15. DEBUG [main] - Checking to see if class com.company.po.Person matches criteria [is assignable to Object]
  16. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
  17. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
  18. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
  19. DEBUG [main] - PooledDataSource forcefully closed/removed all connections.
  20. DEBUG [main] - Opening JDBC Connection
  21. DEBUG [main] - Created connection 1800890735.
  22. DEBUG [main] - Setting autocommit to false on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6b57696f]
  23. DEBUG [main] - ==>  Preparing: select * from tb_person where id=? 
  24. DEBUG [main] - ==> Parameters: 2(Integer)
  25. DEBUG [main] - ====>  Preparing: select * from tb_idcard where id=? 
  26. DEBUG [main] - ====> Parameters: 2(Integer)
  27. DEBUG [main] - <====      Total: 1
  28. DEBUG [main] - <==      Total: 1
  29. Person [id=2, name=Tom, age=29, sex=male, card=idCard [id=2, code=440883199808082121]]
  30. DEBUG [main] - Resetting autocommit to true on JDBC Connection [com.mysql.jdbc.JDBC4Connection@6b57696f]
  31. DEBUG [main] - Closing JDBC Connection [com.mysql.jdbc.JDBC4Connection@6b57696f]
  32. DEBUG [main] - Returned connection 1800890735 to pool.
     

本人在运行mybatis相关代码时,因为这个问题弄了很久才发现,在网上相关的资料比较少,在此分享给大家!欢迎吐槽!!!

错误日志配置:

  1. # Global logging configuration
  2. log4j.rootLogger=DEBUG, stdout
  3. # Console output...
  4. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  5. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  6. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

 

正确日志配置:

  1. # Global logging configuration
  2. log4j.rootLogger=ERROR, stdout
  3. # MyBatis logging configuration...
  4. log4j.logger.com.company=DEBUG
  5. # Console output...
  6. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  7. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  8. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

原因:少配置的部分是(正确配置部分)第三/第四行代码,以及第二行DEBUG(错误)和ERROR(正确)不同

 

 

 

关注公众号ITCBL,即可得到更多分享哦!

"C:\Program Files\Java\jdk-22\bin\java.exe" "-javaagent:C:\Users\Administrator\AppData\Local\JetBrains\IntelliJIdea2025.2\captureAgent\debugger-agent.jar=file:///C:/Users/ADMINI~1/AppData/Local/Temp/capture6298041499272897976.props" -ea -Didea.test.cyclic.buffer.size=1048576 "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2025.2\lib\idea_rt.jar=63160" -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Ddebugger.agent.enable.coroutines=true -Dkotlinx.coroutines.debug.enable.flows.stack.trace=true -Dkotlinx.coroutines.debug.enable.mutable.state.flows.stack.trace=true -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2025.2\lib\idea_rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2025.2\plugins\junit\lib\junit5-rt.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2025.2\plugins\junit\lib\junit-rt.jar;C:\Users\Administrator\IdeaProjects\Mybatis2\target\test-classes;C:\Users\Administrator\IdeaProjects\Mybatis2\target\classes;C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\8.0.11\mysql-connector-java-8.0.11.jar;C:\Users\Administrator\.m2\repository\com\google\protobuf\protobuf-java\2.6.0\protobuf-java-2.6.0.jar;C:\Users\Administrator\.m2\repository\org\mybatis\mybatis\3.4.5\mybatis-3.4.5.jar;C:\Users\Administrator\.m2\repository\junit\junit\4.13\junit-4.13.jar;C:\Users\Administrator\.m2\repository\org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar;C:\Users\Administrator\.m2\repository\org\slf4j\slf4j-api\1.7.20\slf4j-api-1.7.20.jar;C:\Users\Administrator\.m2\repository\ch\qos\logback\logback-classic\1.2.3\logback-classic-1.2.3.jar;C:\Users\Administrator\.m2\repository\ch\qos\logback\logback-core\1.2.3\logback-core-1.2.3.jar" com.intellij.rt.junit.JUnitStarter -ideVersion5 -junit4 MyTest,testFindUserByUnameandAge [DEBUG] [main] o.a.i.l.LogFactory - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter. [DEBUG] [main] o.a.i.d.p.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [DEBUG] [main] o.a.i.d.p.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [DEBUG] [main] o.a.i.d.p.PooledDataSource - PooledDataSource forcefully closed/removed all connections. [DEBUG] [main] o.a.i.d.p.PooledDataSource - PooledDataSource forcefully closed/removed all connections. org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for UserMapper.findUserByUnameandAge ### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for UserMapper.findUserByUnameandAge at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at MyTest.testFindUserByUnameandAge(MyTest.java:20) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63) at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329) at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293) at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306) at org.junit.runners.ParentRunner.run(ParentRunner.java:413) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38) at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:231) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:55) Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for UserMapper.findUserByUnameandAge at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:888) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:721) at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:714) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) ... 27 more 进程已结束,退出代码为 -1
10-23
C:\Users\zhoux\.jdks\openjdk-25\bin\java.exe --enable-preview "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.3\lib\idea_rt.jar=50074" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath D:\code\untitled2\out\production\untitled2;C:\Users\zhoux\.m2\repository\org\mybatis\mybatis\3.5.19\mybatis-3.5.19.jar com.unit15.entity.test.test Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter. PooledDataSource forcefully closed/removed all connections. PooledDataSource forcefully closed/removed all connections. PooledDataSource forcefully closed/removed all connections. PooledDataSource forcefully closed/removed all connections. Opening JDBC Connection org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. ### The error may exist in mapper/UserMapper.xml ### The error may involve mapper.UserMapper.findAllUser ### The error occurred while executing a query ### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:156) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:142) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:137) at com.unit15.entity.test.test.main(test.java:22) Caused by: java.sql.SQLException: Error setting driver on UnpooledDataSource. at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:252) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:228) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:224) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:97) at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:452) at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:100) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:145) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:67) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:348) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:89) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:64) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:336) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:158) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:110) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:90) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:154) ... 4 more Caused by: java.lang.ClassNotFoundException: Cannot find class: #{db.driver} at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:226) at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:103) at org.apache.ibatis.io.Resources.classForName(Resources.java:322) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.lambda$initializeDriver$0(UnpooledDataSource.java:242) at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1724) at org.apache.ibatis.util.MapUtil.computeIfAbsent(MapUtil.java:36) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:236) ... 19 more
最新发布
10-24
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值