{"id":203152,"date":"2025-05-22T12:47:59","date_gmt":"2025-05-22T04:47:59","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203152\/"},"modified":"2025-05-22T12:47:59","modified_gmt":"2025-05-22T04:47:59","slug":"springboot-%e9%a1%b9%e7%9b%ae%e8%bf%90%e8%a1%8c%e6%97%b6%e7%aa%81%e7%8e%b0%e7%a5%9e%e7%a7%98%e9%94%99%e8%af%af%ef%bc%9asqlsession-%e6%9c%aa%e6%b3%a8%e5%86%8c%ef%bc%8c%e9%a1%b9%e7%9b%ae%e4%bb%a3","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203152\/","title":{"rendered":"SpringBoot \u9879\u76ee\u8fd0\u884c\u65f6\u7a81\u73b0\u795e\u79d8\u9519\u8bef\uff1aSqlSession \u672a\u6ce8\u518c\uff0c\u9879\u76ee\u4ee3\u7801\u65e0\u6539\u52a8\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>SpringBoot \u9879\u76ee\u8fd0\u884c\u65f6\u7a81\u73b0\u795e\u79d8\u9519\u8bef\uff1aSqlSession \u672a\u6ce8\u518c\uff0c\u9879\u76ee\u4ee3\u7801\u65e0\u6539\u52a8\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u7ed9\u5927\u5bb6\u5206\u4eab\u300aSpringBoot \u9879\u76ee\u8fd0\u884c\u65f6\u7a81\u73b0\u795e\u79d8\u9519\u8bef\uff1aSqlSession \u672a\u6ce8\u518c\uff0c\u9879\u76ee\u4ee3\u7801\u65e0\u6539\u52a8\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u300b\uff0c\u8986\u76d6\u4e86\u6587\u7ae0\u7684\u5e38\u89c1\u57fa\u7840\u77e5\u8bc6\uff0c\u5176\u5b9e\u4e00\u4e2a\u8bed\u8a00\u7684\u5168\u90e8\u77e5\u8bc6\u70b9\u4e00\u7bc7\u6587\u7ae0\u662f\u4e0d\u53ef\u80fd\u8bf4\u5b8c\u7684\uff0c\u4f46\u5e0c\u671b\u901a\u8fc7\u8fd9\u4e9b\u95ee\u9898\uff0c\u8ba9\u8bfb\u8005\u5bf9\u81ea\u5df1\u7684\u638c\u63e1\u7a0b\u5ea6\u6709\u4e00\u5b9a\u7684\u8ba4\u8bc6(B \u6570)\uff0c\u4ece\u800c\u5f25\u8865\u81ea\u5df1\u7684\u4e0d\u8db3\uff0c\u66f4\u597d\u7684\u638c\u63e1\u5b83\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241030\/17302644456721bd7dcd2a0.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>springboot \u9879\u76ee\u8fd0\u884c\u65f6\u7a81\u73b0\u795e\u79d8\u9519\u8bef<\/strong><\/p>\n<p>\u8fd1\u671f\uff0c\u4e00\u4f4d\u5f00\u53d1\u4eba\u5458\u5728springboot\u9879\u76ee\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u906d\u9047\u4e86\u4e00\u4e2a\u56f0\u6270\u5176\u8bb8\u4e45\u7684\u9519\u8bef\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>\u4ee4\u4eba\u8be7\u5f02\u7684\u662f\uff0c\u9879\u76ee\u4ee3\u7801\u5e76\u672a\u505a\u4efb\u4f55\u6539\u52a8\uff0c\u4ee5\u5f80\u8fd0\u884c\u826f\u597d\u3002\u56f0\u60d1\u4e0d\u89e3\u7684\u5f00\u53d1\u4eba\u5458\u5728\u7f51\u4e0a\u82e6\u82e6\u641c\u5bfb\u7b54\u6848\uff0c\u5374\u53d1\u73b0\u8fd9\u4e2a\u9519\u8bef\u5e76\u4e0d\u662f\u5e38\u89c1\u7684\u4ee3\u7801\u9519\u8bef\u3002<\/p>\n<p>\u8fdb\u4e00\u6b65\u6392\u67e5\uff0c\u5f00\u53d1\u4eba\u5458\u68c0\u67e5\u4e86\u9879\u76ee\u7684yml\u914d\u7f6e\u6587\u4ef6\uff0c\u53d1\u73b0\u76f8\u5173\u914d\u7f6e\u5982\u4e0b\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>\u68c0\u67e5\u914d\u7f6e\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u53d1\u73b0\u5e76\u6ca1\u6709\u660e\u663e\u7684\u9519\u8bef\u3002\u6b63\u5f53\u4ed6\u4e00\u7b79\u83ab\u5c55\u4e4b\u9645\uff0c\u4e00\u4f4d\u7ecf\u9a8c\u4e30\u5bcc\u7684\u7a0b\u5e8f\u5458\u4e3a\u4ed6\u6307\u70b9\u4e86\u4e00\u6761\u660e\u8def\uff1a<\/p>\n<p><strong>\u89e3\u51b3\u529e\u6cd5\uff1a<\/strong><\/p>\n<p>\u524d\u5f80 csdn \u535a\u5ba2\u7f51\u5740 https:\/\/blog.csdn.net\/web1829&#8230;\uff0c\u67e5\u770b\u4e00\u7bc7\u9898\u4e3a\u300asqlsession [org.apache.ibatis.session.defaults.defaultsqlsession@2dbe837b] was not registered for synchronization because synchronization is not active\u300b\u7684\u6587\u7ae0\u3002<\/p>\n<p>\u8fd9\u7bc7\u6587\u7ae0\u8be6\u7ec6\u5206\u6790\u4e86\u5bfc\u81f4\u8be5\u9519\u8bef\u7684\u539f\u56e0\uff0c\u5e76\u7ed9\u51fa\u4e86\u76f8\u5e94\u7684\u89e3\u51b3\u65b9\u6848\u3002\u6309\u7167\u6587\u7ae0\u4e2d\u7684\u6307\u5bfc\uff0c\u5f00\u53d1\u4eba\u5458\u5728\u9879\u76ee\u4e2d\u6dfb\u52a0\u4e86\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<pre>@Configuration\npublic class MyBatisConfig {\n\n  @Bean\n  @Scope(\"prototype\")\n  @Primary\n  public SqlSessionFactory sqlSessionFactory(@Qualifier(\"dataSource\") DataSource dataSource) {\n    return new SqlSessionFactoryBean().getObject();\n  }\n}<\/pre>\n<p>\u6dfb\u52a0\u4ee3\u7801\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u91cd\u65b0\u542f\u52a8\u9879\u76ee\uff0c\u9519\u8bef\u6d88\u5931\uff0c\u9879\u76ee\u6062\u590d\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aSpringBoot \u9879\u76ee\u8fd0\u884c\u65f6\u7a81\u73b0\u795e\u79d8\u9519\u8bef\uff1aSqlSession \u672a\u6ce8\u518c\uff0c\u9879\u76ee\u4ee3\u7801\u65e0\u6539\u52a8\uff0c\u8be5\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SpringBoot \u9879\u76ee\u8fd0\u884c\u65f6&#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-203152","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203152","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=203152"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203152\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}