{"id":203145,"date":"2025-05-22T10:48:18","date_gmt":"2025-05-22T02:48:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203145\/"},"modified":"2025-05-22T10:48:18","modified_gmt":"2025-05-22T02:48:18","slug":"springboot%e9%a1%b9%e7%9b%ae%e8%bf%90%e8%a1%8c%e6%8a%a5%e9%94%99%ef%bc%9asqlsession%e6%b3%a8%e5%86%8c%e5%a4%b1%e8%b4%a5%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3creating-a-new-sqlsession","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203145\/","title":{"rendered":"SpringBoot\u9879\u76ee\u8fd0\u884c\u62a5\u9519\uff1aSqlSession\u6ce8\u518c\u5931\u8d25\uff0c\u5982\u4f55\u89e3\u51b3\u201cCreating a new SqlSession&#8230; was not registered for synchronization\u2026\u201d\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>SpringBoot\u9879\u76ee\u8fd0\u884c\u62a5\u9519\uff1aSqlSession\u6ce8\u518c\u5931\u8d25\uff0c\u5982\u4f55\u89e3\u51b3\u201cCreating a new SqlSession&#8230; was not registered for synchronization\u2026\u201d\uff1f <\/h1>\n<p>\u7f16\u7a0b\u5e76\u4e0d\u662f\u4e00\u4e2a\u673a\u68b0\u6027\u7684\u5de5\u4f5c\uff0c\u800c\u662f\u9700\u8981\u6709\u601d\u8003\uff0c\u6709\u521b\u65b0\u7684\u5de5\u4f5c\uff0c\u8bed\u6cd5\u662f\u56fa\u5b9a\u7684\uff0c\u4f46\u89e3\u51b3\u95ee\u9898\u7684\u601d\u8def\u5219\u662f\u4f9d\u9760\u4eba\u7684\u601d\u7ef4\uff0c\u8fd9\u5c31\u9700\u8981\u6211\u4eec\u575a\u6301\u5b66\u4e60\u548c\u66f4\u65b0\u81ea\u5df1\u7684\u77e5\u8bc6\u3002\u4eca\u5929\u5c31\u6574\u7406\u5206\u4eab\u300aSpringBoot\u9879\u76ee\u8fd0\u884c\u62a5\u9519\uff1aSqlSession\u6ce8\u518c\u5931\u8d25\uff0c\u5982\u4f55\u89e3\u51b3\u201cCreating a new SqlSession&#8230; was not registered for synchronization\u2026\u201d\uff1f \u300b\uff0c\u6587\u7ae0\u8bb2\u89e3\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u5305\u62ec\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u65b9\u9762\u7684\u77e5\u8bc6\u70b9\u611f\u5174\u8da3\uff0c\u5c31\u4e0d\u8981\u9519\u8fc7\uff0c\u5728\u8fd9\u53ef\u4ee5\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5f00\u53d1\u80fd\u529b\u7684\u63d0\u5347\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302599516721abef67752.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>springboot\u9879\u76ee\u8fd0\u884c\u62a5\u9519\uff1asqlsession\u6ce8\u518c\u5931\u8d25<\/strong><\/p>\n<p>\u60a8\u7684springboot\u9879\u76ee\u5728\u672a\u4fee\u6539\u4efb\u4f55\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u7a81\u7136\u51fa\u73b0 &#8220;creating a new sqlsession&#8230; was not registered for synchronization&#8230;&#8221; \u7684\u9519\u8bef\uff0c\u4ee4\u4eba\u56f0\u60d1\u4e0d\u89e3\u3002\u5177\u4f53\u62a5\u9519\u5982\u4e0b\uff1a<\/p>\n<pre>creating a new sqlsession\nsqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@2dbe837b] was not registered for synchronization because synchronization is not active<\/pre>\n<p>\u68c0\u67e5\u4e86\u914d\u7f6e\u6587\u4ef6\uff0c\u53d1\u73b0\u5982\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>server:\n  port: 8080\nspring:\n  datasource:\n    druid:\n      driver-class-name: com.mysql.cj.jdbc.Driver\n      url: jdbc:mysql:\/\/110.35.20.7:3306\/cos?useUnicode=true&amp;characterEncoding=utf8&amp;autoReconnect=true&amp;allowMultiQueries=true&amp;zeroDateTimeBehavior=convertToNull&amp;useSSL=false&amp;serverTimezone=Asia\/Shanghai\n      username: mes_it\n      password: 123456\n\nmybatis-plus:\n  config-location: classpath:mybatis\/mybatis-config.xml\n  mapper-locations: classpath:mybatis\/mapper\/*.xml<\/pre>\n<p>\u7136\u800c\uff0c\u8fd9\u4f3c\u4e4e\u6ca1\u6709\u4ec0\u4e48\u95ee\u9898\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u53ef\u4ee5\u53c2\u8003\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>[mybatis-plus\u62a5\u9519\uff1acreating a new sqlsession&#8230; was not registered for synchronization because synchronization is not active &#8211; csdn\u535a\u5ba2](https:\/\/blog.csdn.net\/web1829&#8230;)<\/li>\n<\/ul>\n<p>\u8be5\u94fe\u63a5\u63d0\u4f9b\u4e86\u8be6\u7ec6\u7684\u5206\u6790\u548c\u89e3\u51b3\u65b9\u6848\uff0c\u503c\u5f97\u4e00\u8bd5\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300aSpringBoot\u9879\u76ee\u8fd0\u884c\u62a5\u9519\uff1aSqlSession\u6ce8\u518c\u5931\u8d25\uff0c\u5982\u4f55\u89e3\u51b3\u201cCreating a new SqlSession&#8230; was not registered for synchronization\u2026\u201d\uff1f \u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot\u9879\u76ee\u8fd0\u884c\u62a5\u9519&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203145","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203145","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203145"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203145\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}