“SqlSession[xxx] was not registered for synchronization because synchronization is not active”问题成功解决

“SqlSession[xxx] was not registered for synchronization because synchronization is not active”问题成功解决,第1张

一、问题详情:

        spring boot项目控制台打印如下日志,但程序可正常运行,并未报错:

​​​​D:\JavaJDK\jdk1.8.0_261\bin\java.exe -XX:TieredStopAtLevel=1 -noverify -Dspring.output.ansi.enabled=always "-javaagent:D:\idea安装包\IntelliJ IDEA 2021.2.1\lib\idea_rt.jar=53940:D:\idea安装包\IntelliJ IDEA 2021.2.1\bin" -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true -Dfile.encoding=UTF-8 -classpath D:\JavaJDK\jdk1.8.0_261\jre\lib\charsets.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\deploy.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\access-bridge-64.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\cldrdata.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\dnsns.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\jaccess.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\jfxrt.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\localedata.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\nashorn.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\sunec.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\sunjce_provider.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\sunmscapi.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\sunpkcs11.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\ext\zipfs.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\javaws.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\jce.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\jfr.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\jfxswt.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\jsse.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\management-agent.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\plugin.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\resources.jar;D:\JavaJDK\jdk1.8.0_261\jre\lib\rt.jar;E:\idea\javaee19-2\spring_mybatic\target\classes;C:\Users\2799732726\AppData\Roaming\JetBrains\IntelliJIdea2021.2\javascript\extLibs\http_cdn.staticfile.org_vue_2.4.2_vue.js;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter-web\2.6.4\spring-boot-starter-web-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter\2.6.4\spring-boot-starter-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot\2.6.4\spring-boot-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-autoconfigure\2.6.4\spring-boot-autoconfigure-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter-logging\2.6.4\spring-boot-starter-logging-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\ch\qos\logback\logback-classic\1.2.10\logback-classic-1.2.10.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\ch\qos\logback\logback-core\1.2.10\logback-core-1.2.10.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\apache\logging\log4j\log4j-to-slf4j\2.17.1\log4j-to-slf4j-2.17.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\apache\logging\log4j\log4j-api\2.17.1\log4j-api-2.17.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-core\5.3.16\spring-core-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-jcl\5.3.16\spring-jcl-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter-json\2.6.4\spring-boot-starter-json-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\core\jackson-databind\2.13.1\jackson-databind-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\core\jackson-annotations\2.13.1\jackson-annotations-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\core\jackson-core\2.13.1\jackson-core-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\datatype\jackson-datatype-jdk8\2.13.1\jackson-datatype-jdk8-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\datatype\jackson-datatype-jsr310\2.13.1\jackson-datatype-jsr310-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\fasterxml\jackson\module\jackson-module-parameter-names\2.13.1\jackson-module-parameter-names-2.13.1.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter-tomcat\2.6.4\spring-boot-starter-tomcat-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\apache\tomcat\embed\tomcat-embed-core\9.0.58\tomcat-embed-core-9.0.58.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\apache\tomcat\embed\tomcat-embed-el\9.0.58\tomcat-embed-el-9.0.58.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\apache\tomcat\embed\tomcat-embed-websocket\9.0.58\tomcat-embed-websocket-9.0.58.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-web\5.3.16\spring-web-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-beans\5.3.16\spring-beans-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-webmvc\5.3.16\spring-webmvc-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-aop\5.3.16\spring-aop-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-context\5.3.16\spring-context-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-expression\5.3.16\spring-expression-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\mybatis\spring\boot\mybatis-spring-boot-starter\2.1.4\mybatis-spring-boot-starter-2.1.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\boot\spring-boot-starter-jdbc\2.6.4\spring-boot-starter-jdbc-2.6.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\com\zaxxer\HikariCP\4.0.3\HikariCP-4.0.3.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-jdbc\5.3.16\spring-jdbc-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\springframework\spring-tx\5.3.16\spring-tx-5.3.16.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\mybatis\spring\boot\mybatis-spring-boot-autoconfigure\2.1.4\mybatis-spring-boot-autoconfigure-2.1.4.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\mybatis\mybatis\3.5.6\mybatis-3.5.6.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\org\mybatis\mybatis-spring\2.0.6\mybatis-spring-2.0.6.jar;D:\MAVEN安装包\apache-maven-3.8.2\maven-repo\mysql\mysql-connector-java\5.1.45\mysql-connector-java-5.1.45.jar com.SpringMysticApplication

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.6.4)

2022-03-11 16:35:26.438  INFO 7352 --- [           main] com.SpringMysticApplication              : Starting SpringMysticApplication using Java 1.8.0_261 on 沐曦辰 with PID 7352 (E:\idea\javaee19-2\spring_mybatic\target\classes started by 2799732726 in E:\idea\javaee19-2)
2022-03-11 16:35:26.439  INFO 7352 --- [           main] com.SpringMysticApplication              : The following 1 profile is active: "default"
2022-03-11 16:35:27.338  INFO 7352 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2022-03-11 16:35:27.343  INFO 7352 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2022-03-11 16:35:27.343  INFO 7352 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.58]
2022-03-11 16:35:27.390  INFO 7352 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2022-03-11 16:35:27.391  INFO 7352 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 926 ms
Logging initialized using 'class org.apache.ibatis.logging.stdout.StdOutImpl' adapter.
Parsed mapper file: 'file [E:\idea\javaee19-2\spring_mybatic\target\classes\mapper\customerMapper.xml]'
Parsed mapper file: 'file [E:\idea\javaee19-2\spring_mybatic\target\classes\mapper\studentMapper.xml]'
2022-03-11 16:35:27.804  INFO 7352 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2022-03-11 16:35:27.810  INFO 7352 --- [           main] com.SpringMysticApplication              : Started SpringMysticApplication in 1.603 seconds (JVM running for 2.103)
2022-03-11 16:35:34.801  INFO 7352 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2022-03-11 16:35:34.801  INFO 7352 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2022-03-11 16:35:34.802  INFO 7352 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@37ad2985] was not registered for synchronization because synchronization is not active
2022-03-11 16:35:34.852  INFO 7352 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2022-03-11 16:35:34.970  INFO 7352 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
JDBC Connection [HikariProxyConnection@1020688105 wrapping com.mysql.jdbc.JDBC4Connection@277aa294] will not be managed by Spring
==>  Preparing: select * from mybatic.customer limit 0,?
==> Parameters: 2(Integer)
<==    Columns: id, username, jobs, phone
<==        Row: 2, 小李, 教授, 132131
<==        Row: 3, 李明, 教授, 132131
<==      Total: 2
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@37ad2985]

        上述错误讲述的是:Sqlsession未注册同步,同步注册未激活,JDBC connection不能被Spring所托管

二、解决方法:                               

        网上讲述众说纷纭,但看了好多帖子都未能有有效的解决方法,有的帖子写的是配置文件出错,但我的项目是可以运行,只是在控制台打印sql语句时出现了如下问题:

        经过长时间的探索,最终发现控制台报这个错的原因是:service实现类方法上未加@transactional  注解,从而导致地未同步注册。

            在实现类方法上加入该注解后,问题得到了解决

 

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/991304.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存