{"id":203923,"date":"2025-05-22T14:28:39","date_gmt":"2025-05-22T06:28:39","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203923\/"},"modified":"2025-05-22T14:28:39","modified_gmt":"2025-05-22T06:28:39","slug":"mybatis-%e6%8a%a5%e9%94%99-property-sqlsessionfactory-or-sqlsessiontemplate-are-required-%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203923\/","title":{"rendered":"Mybatis \u62a5\u9519 \\&#8221;Property \\&#8217;sqlSessionFactory\\&#8217; or \\&#8217;sqlSessionTemplate\\&#8217; are required\\&#8221; \u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Mybatis \u62a5\u9519 \\&#8221;Property \\&#8217;sqlSessionFactory\\&#8217; or \\&#8217;sqlSessionTemplate\\&#8217; are required\\&#8221; \u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aMybatis \u62a5\u9519 \\&#8221;Property \\&#8217;sqlSessionFactory\\&#8217; or \\&#8217;sqlSessionTemplate\\&#8217; are required\\&#8221; \u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241201\/1733014481674bb3d1d3b2f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u89e3\u51b3 &#8220;Property &#8216;sqlSessionFactory&#8217; or &#8216;sqlSessionTemplate&#8217; are required&#8221; \u95ee\u9898<\/strong><\/p>\n<p>\u5f53\u5904\u7406 &#8220;Property &#8216;sqlSessionFactory&#8217; or &#8216;sqlSessionTemplate&#8217; are required&#8221; \u9519\u8bef\u65f6\uff0c\u8fd9\u662f Mybatis \u629b\u51fa\u7684\u5f02\u5e38\uff0c\u8868\u660e\u5728\u914d\u7f6e\u4e2d\u7f3a\u5c11\u5fc5\u9700\u7684 bean\u3002<\/p>\n<p><strong>\u95ee\u9898\u4ea7\u751f\u7684\u539f\u56e0<\/strong><\/p>\n<p>\u6b64\u95ee\u9898\u901a\u5e38\u662f\u7531\u4ee5\u4e0b\u539f\u56e0\u5f15\u8d77\u7684\uff1a<\/p>\n<ul>\n<li>Mybatis \u914d\u7f6e\u6216\u4f9d\u8d56\u9879\u7248\u672c\u4e0d\u6b63\u786e<\/li>\n<li>MyBatis-Spring JAR \u6587\u4ef6\u672a\u6b63\u786e\u5305\u542b<\/li>\n<li>\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4e0b\u6587\u4e2d\u7f3a\u5c11\u9002\u5f53\u7684 bean \u5b9a\u4e49<\/li>\n<\/ul>\n<p><strong>\u5df2\u5c1d\u8bd5\u7684\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u60a8\u63d0\u5230\u5df2\u5c06 MyBatis-Plus \u7684\u7248\u672c\u66f4\u6539\u4e3a 3.4.2\uff0c\u4f46\u95ee\u9898\u4ecd\u7136\u5b58\u5728\u3002<\/p>\n<p><strong>\u6b63\u786e\u7b54\u6848<\/strong><\/p>\n<p>\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ul>\n<li>\u68c0\u67e5\u60a8\u7684 pom.xml \u6587\u4ef6\uff0c\u786e\u4fdd\u5df2\u6b63\u786e\u5305\u542b MyBatis-Spring \u7684\u4f9d\u8d56\u9879\uff08\u4f8b\u5982\uff0c&lt;dependency&gt;&#8230;&lt;\/dependency&gt;\uff09\u3002<\/li>\n<li>\u9a8c\u8bc1\u60a8\u7684 Mybatis \u914d\u7f6e\u6587\u4ef6\u4e2d\u7684 bean \u5b9a\u4e49\uff0c\u4f8b\u5982 &lt;bean id=&#8221;sqlSessionFactory&#8221; class=&#8221;org.mybatis.spring.SqlSessionFactoryBean&#8221; \/&gt;\u3002<\/li>\n<li>\u786e\u4fdd\u60a8\u6b63\u5728\u4f7f\u7528\u4e0e MyBatis-Plus \u7248\u672c\u517c\u5bb9\u7684 MyBatis \u7248\u672c\u3002\u60a8\u53ef\u4ee5\u5728 MyBatis Spring \u6587\u6863\u4e2d\u627e\u5230\u7279\u5b9a\u7248\u672c\u7684\u517c\u5bb9\u6027\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u63d0\u793a<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u5728\u89e3\u51b3\u6b64\u95ee\u9898\u65f6\u9047\u5230\u56f0\u96be\uff0c\u53ef\u4ee5\u53c2\u8003 MyBatis Spring \u6587\u6863\uff1ahttps:\/\/mybatis.org\/spring\/index.html<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aMybatis \u62a5\u9519 \\&#8221;Property \\&#8217;sqlSessionFactory\\&#8217; or \\&#8217;sqlSessionTemplate\\&#8217; are required\\&#8221; \u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Mybatis \u62a5\u9519 \\&#038;#82&#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-203923","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203923","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=203923"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203923\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203923"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203923"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203923"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}