{"id":66850,"date":"2026-01-27T18:17:30","date_gmt":"2026-01-27T10:17:30","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/66850.html"},"modified":"2026-01-27T18:17:30","modified_gmt":"2026-01-27T10:17:30","slug":"spring%e5%85%a8%e5%ae%b6%e6%a1%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/66850.html","title":{"rendered":"Spring\u5168\u5bb6\u6876"},"content":{"rendered":"<h2>Mybatis<\/h2>\n<h3>\u7f13\u5b58\u673a\u5236<\/h3>\n<p>MyBatis \u63d0\u4f9b\u4e86\u4e24\u7ea7\u7f13\u5b58\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002<\/p>\n<ul>\n<li>\n<p>\u4e00\u7ea7\u7f13\u5b58&#xff08;\u672c\u5730\u7f13\u5b58&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\u4f5c\u7528\u8303\u56f4&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u662f\u5728SqlSession\u7684\u751f\u547d\u5468\u671f\u5185\u6709\u6548&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bcf\u4e2aSqlSession\u62e5\u6709\u72ec\u7acb\u7684\u4e00\u7ea7\u7f13\u5b58\u3002<\/li>\n<li>\u9ed8\u8ba4\u5f00\u542f&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u5728MyBatis\u4e2d\u9ed8\u8ba4\u662f\u5f00\u542f\u7684&#xff0c;\u65e0\u9700\u989d\u5916\u914d\u7f6e\u3002<\/li>\n<li>\u7279\u70b9&#xff1a; \u5f53\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6&#xff0c;\u67e5\u8be2\u7684\u7ed3\u679c\u4f1a\u88ab\u7f13\u5b58\u5728\u5f53\u524dSqlSession\u4e2d\u3002\u5982\u679c\u518d\u6b21\u6267\u884c\u76f8\u540c\u7684\u67e5\u8be2&#xff0c;MyBatis\u4f1a\u9996\u5148\u5c1d\u8bd5\u4ece\u7f13\u5b58\u4e2d\u83b7\u53d6\u6570\u636e&#xff0c;\u800c\u4e0d\u518d\u8bbf\u95ee\u6570\u636e\u5e93\u3002<\/li>\n<li>\u81ea\u52a8\u5237\u65b0&#xff1a; MyBatis\u4f1a\u5728\u6267\u884cinsert\u3001update\u3001delete\u7b49\u5199\u64cd\u4f5c\u65f6\u81ea\u52a8\u6e05\u7a7a\u4e00\u7ea7\u7f13\u5b58&#xff0c;\u4ee5\u4fdd\u6301\u6570\u636e\u7684\u4e00\u81f4\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>\u4e8c\u7ea7\u7f13\u5b58&#xff08;\u5168\u5c40\u7f13\u5b58&#xff09;&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u4f5c\u7528\u8303\u56f4&#xff1a; \u4e8c\u7ea7\u7f13\u5b58\u662f\u5728\u591a\u4e2aSqlSession\u4e4b\u95f4\u5171\u4eab\u7684&#xff0c;\u5373\u591a\u4e2aSqlSession\u53ef\u4ee5\u5171\u4eab\u540c\u4e00\u4e2a\u4e8c\u7ea7\u7f13\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u5f00\u542f&#xff1a; \u4e8c\u7ea7\u7f13\u5b58\u9700\u8981\u624b\u52a8\u914d\u7f6e\u5f00\u542f&#xff0c;\u9700\u8981\u5728\u6620\u5c04\u6587\u4ef6\u7684&lt;mapper&gt;\u6807\u7b7e\u4e0b\u6dfb\u52a0&lt;cache&gt;\u5143\u7d20\u3002<\/p>\n<p> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>cache<\/span><br \/>\n    <span class=\"token attr-name\">eviction<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>LRU<span class=\"token punctuation\">&#034;<\/span><\/span>           <span class=\"token attr-name\">&lt;!&#8211;<\/span> <span class=\"token attr-name\">\u7f13\u5b58\u56de\u6536\u7b56\u7565<\/span> <span class=\"token attr-name\">&#8212;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    flushInterval&#061;&#034;60000&#034;    <span class=\"token comment\">&lt;!&#8211; \u81ea\u52a8\u5237\u65b0\u95f4\u9694(\u6beb\u79d2) &#8211;&gt;<\/span><br \/>\n    size&#061;&#034;1024&#034;              <span class=\"token comment\">&lt;!&#8211; \u7f13\u5b58\u5bf9\u8c61\u6570\u91cf &#8211;&gt;<\/span><br \/>\n    readOnly&#061;&#034;true&#034;&gt;        <span class=\"token comment\">&lt;!&#8211; \u662f\u5426\u53ea\u8bfb &#8211;&gt;<\/span>\n <\/li>\n<li>\n<p>\u7279\u70b9&#xff1a; \u4e8c\u7ea7\u7f13\u5b58\u80fd\u591f\u8de8SqlSession\u5171\u4eab\u67e5\u8be2\u7ed3\u679c&#xff0c;\u6709\u6548\u51cf\u5c11\u6570\u636e\u5e93\u8bbf\u95ee\u6b21\u6570\u3002\u5b83\u7684\u6570\u636e\u5b58\u50a8\u5728\u5168\u5c40\u8303\u56f4\u7684\u7f13\u5b58\u4e2d&#xff0c;\u53ef\u4ee5\u7531\u591a\u4e2aSqlSession\u8bbf\u95ee\u3002<\/p>\n<\/li>\n<li>\n<p>\u7f13\u5b58\u7b56\u7565&#xff1a; \u4f60\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u4e0d\u540c\u7684\u7f13\u5b58\u56de\u6536\u7b56\u7565&#xff08;\u4f8b\u5982LRU-\u6700\u8fd1\u6700\u5c11\u4f7f\u7528\u3001FIFO\u7b49&#xff09;&#xff0c;\u4ee5\u53ca\u914d\u7f6e\u5237\u65b0\u95f4\u9694\u3001\u7f13\u5b58\u7684\u5927\u5c0f\u7b49\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u81ea\u52a8\u5237\u65b0&#xff1a; MyBatis\u4f1a\u5728\u6267\u884cinsert\u3001update\u3001delete\u7b49\u5199\u64cd\u4f5c\u65f6&#xff08;\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027&#xff09;\u3001\u5230\u8fbe flushInterval \u6307\u5b9a\u65f6\u95f4\u65f6&#xff08;\u9632\u6b62\u7f13\u5b58\u957f\u65f6\u95f4\u9648\u65e7&#xff09;\u81ea\u52a8\u6e05\u7a7a\u4e8c\u7ea7\u7f13\u5b58<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u610f\u4e8b\u9879&#xff1a; \u4e8c\u7ea7\u7f13\u5b58\u53ef\u4ee5\u7f13\u5b58\u7684\u5bf9\u8c61\u5fc5\u987b\u5b9e\u73b0 Serializable \u63a5\u53e3&#xff0c;\u4ee5\u786e\u4fdd\u80fd\u591f\u6b63\u786e\u5e8f\u5217\u5316\u548c\u53cd\u5e8f\u5217\u5316\u3002\u6b64\u5916&#xff0c;MyBatis \u7684\u4e8c\u7ea7\u7f13\u5b58\u662f\u57fa\u4e8e Mapper&#xff08;namespace&#xff09;\u7684&#xff0c;\u4e0d\u662f\u57fa\u4e8e\u8868\u7684&#xff0c;\u56e0\u6b64\u5bf9\u4e8e\u5173\u8054\u6570\u636e\u7684\u66f4\u65b0\u64cd\u4f5c&#xff08;\u5982\u66f4\u65b0 A \u8868\u540e\u5f71\u54cd B \u8868\u7684\u67e5\u8be2\u7ed3\u679c&#xff09;&#xff0c;\u9700\u8981\u624b\u52a8\u6e05\u9664\u76f8\u5173\u7684\u4e8c\u7ea7\u7f13\u5b58\u6216\u4f7f\u7528 &#064;CacheNamespaceRef \u6ce8\u89e3\u6765\u5efa\u7acb\u7f13\u5b58\u5173\u7cfb&#xff0c;\u4ee5\u907f\u514d\u810f\u6570\u636e\u7684\u95ee\u9898\u3002<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>\u5ef6\u8fdf\u52a0\u8f7d<\/h3>\n<p>\u6240\u8c13\u7684\u5ef6\u8fdf\u52a0\u8f7d&#xff0c;\u5176\u5b9e\u5c31\u662f\u4e00\u79cd\u4f18\u5316\u65b9\u6cd5&#xff0c;\u76ee\u6807\u662f\u4e3a\u4e86\u5728\u67e5\u6570\u636e\u5e93\u7684\u65f6\u5019&#xff0c;\u5c3d\u91cf\u4e0d\u8bfb\u53d6\u591a\u4f59\u7684\u6570\u636e&#xff0c;\u4ece\u800c\u63d0\u9ad8\u6211\u4eec\u5e94\u7528\u7684\u8868\u73b0\u548c\u8282\u7ea6\u8d44\u6e90\u3002<\/p>\n<p>Mybatis\u4ec5\u652f\u6301association\u5173\u8054\u5bf9\u8c61\u548ccollection\u5173\u8054\u96c6\u5408\u5bf9\u8c61\u7684\u5ef6\u8fdf\u52a0\u8f7d&#xff0c;association\u6307\u7684\u5c31\u662f\u4e00 \u5bf9\u4e00&#xff0c;collection\u6307\u7684\u5c31\u662f\u4e00\u5bf9\u591a\u67e5\u8be2\u3002<\/p>\n<p>\u5728Mybatis\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u53ef\u4ee5\u914d\u7f6e\u662f\u5426\u542f\u7528\u5ef6\u8fdf\u52a0\u8f7d lazyLoadingEnabled&#061;true|false\u3002<\/p>\n<p>\u5047\u8bbe\u6709\u4e24\u5f20\u8868&#xff0c;\u4e00\u5f20\u662f\u8ba2\u5355\u8868&#xff0c;\u53e6\u4e00\u5f20\u662f\u5546\u54c1\u8868\u3002\u6bcf\u4e2a\u8ba2\u5355\u4e0b\u9762\u53ef\u80fd\u6709\u597d\u51e0\u4e2a\u5546\u54c1\u3002\u7528\u5ef6\u8fdf\u52a0\u8f7d\u7684\u8bdd&#xff0c;\u5f53\u6211\u4eec\u67e5\u4e00\u4e2a\u8ba2\u5355\u7684\u65f6\u5019&#xff0c;MyBatis\u4e0d\u4f1a\u9a6c\u4e0a\u67e5\u51fa\u8fd9\u4e2a\u8ba2\u5355\u7684\u6240\u6709\u5546\u54c1&#xff0c;\u800c\u662f\u7b49\u5230\u6211\u4eec\u771f\u7684\u8981\u7528\u5546\u54c1\u7684\u6570\u636e\u65f6\u624d\u53bb\u67e5\u3002\u8fd9\u6837\u505a\u5c31\u907f\u514d\u4e86\u5728\u67e5\u8ba2\u5355\u7684\u65f6\u5019\u989d\u5916\u52a0\u8f7d\u4e86\u4e00\u5806\u6ca1\u7528\u7684\u5546\u54c1\u3002<\/p>\n<hr \/>\n<h3>#{}\u548c${}\u7684\u533a\u522b\u662f\u4ec0\u4e48&#xff1f;<\/h3>\n<p># \u548c $<\/p>\n<p>\u6211\u4eec\u5148\u6765\u770b # \u7684\u7528\u6cd5&#xff1a;<\/p>\n<p>select * from t_user where name &#061; #{param}<\/p>\n<p>\u5982\u679c\u60f3\u6267\u884c\u76f8\u540c\u7684 SQL&#xff0c;\u7528 $ \u5199\u6cd5\u5982\u4e0b&#xff1a;<\/p>\n<p>select * from t_user where name &#061; &#039;${param}&#039;<\/p>\n<ul>\n<li># \u4f1a\u8fdb\u884c\u9884\u7f16\u8bd1&#xff0c;\u800c\u4e14\u4f1a\u8fdb\u884c\u7c7b\u578b\u5339\u914d&#xff0c;\u53c2\u6570\u662f\u5728\u7f16\u8bd1\u4e4b\u540e\u586b\u5145\u8fdb\u53bb\u7684&#xff0c;\u6240\u4ee5\u4e0d\u9700\u8981\u52a0\u4e0a\u5355\u5f15\u53f7&#xff1b;<\/li>\n<li>$ \u4e0d\u4f1a\u8fdb\u884c\u6570\u636e\u7c7b\u578b\u7684\u5339\u914d&#xff0c;\u53ea\u662f\u5355\u7eaf\u5730\u8fdb\u884c\u5b57\u7b26\u4e32\u7684\u62fc\u63a5&#xff0c;\u6240\u4ee5\u8981\u81ea\u5df1\u624b\u52a8\u52a0\u4e0a\u5355\u5f15\u53f7&#xff0c;\u5426\u5219\u6700\u7ec8\u62fc\u63a5\u51fa\u6765\u7684SQL\u8bed\u53e5\u5c31\u4e0d\u5bf9\u4e86\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u5c31\u8ddfJDBC\u4e2d\u7684Prepare Statement\u548cStatement\u7684\u533a\u522b\u662f\u4e00\u6837\u7684&#xff0c;\u4f7f\u7528 # \u5c31\u76f8\u5f53\u4e8e\u4f7f\u7528 PrepareStatement&#xff08;\u9884\u7f16\u8bd1\u7684\u53c2\u6570\u5316\u6267\u884c\u5668&#xff09;&#xff0c;\u800c\u4f7f\u7528 $ \u5c31\u76f8\u5f53\u4e8e\u4f7f\u7528 Statement&#xff08;\u76f4\u63a5\u62fc\u63a5 SQL \u7684\u9759\u6001\u6267\u884c\u5668&#xff09;\u3002<\/p>\n<p>\u4ec0\u4e48\u662fSQL\u6ce8\u5165<\/p>\n<p>\u5728CURD\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u4ee5SQL\u67e5\u8be2\u4e3a\u4f8b&#xff0c;\u5047\u8bbe\u6211\u4eec\u60f3\u6839\u636e\u7528\u6237\u540d\u548c\u5bc6\u7801\u67e5\u8be2\u67d0\u4e00\u4e2a\u7528\u6237\u662f\u5426\u5b58\u5728&#xff0c;\u73b0\u5728\u8981\u8ba9\u7528\u6237\u5728\u524d\u7aef\u6839\u636e\u7528\u6237\u540d\u548c\u5bc6\u7801\u8fdb\u884c\u67e5\u8be2\u3002<\/p>\n<p>\u73b0\u5728\u5047\u8bbe\u6211\u4eec\u540e\u53f0\u7684SQL\u8bed\u53e5\u5982\u4e0b&#xff1a;<\/p>\n<p>select * from user where username&#061;&#039;${username}&#039; and password&#061;&#039;${password}&#039;<\/p>\n<p>\u524d\u7aef\u7f51\u9875\u6709\u4e24\u4e2a\u8f93\u5165\u6846&#xff0c;\u4e00\u4e2a\u662f\u7528\u6237\u540d\u8f93\u5165\u6846&#xff0c;\u53e6\u4e00\u4e2a\u662f\u5bc6\u7801\u8f93\u5165\u6846\u3002\u5047\u8bbe\u7528\u6237\u8001\u8001\u5b9e\u5b9e\u5730\u8f93\u5165\u7528\u6237\u540d\u4e3azhangsan&#xff0c;\u5bc6\u7801\u4e3a123&#xff0c;\u90a3\u4e48\u6700\u7ec8\u751f\u6210\u7684SQL\u8bed\u53e5\u5982\u4e0b&#xff1a;<\/p>\n<p>select * from user where username&#061;&#039;zhangsan&#039; and password&#061;&#039;123&#039;<\/p>\n<p>\u4ee5\u4e0a\u8fc7\u7a0b\u4f3c\u4e4e\u5f88\u5b8c\u7f8e&#xff01;<\/p>\n<p>\u4f46\u662f&#xff01;&#xff01;&#xff01;\u8981\u662f\u6709\u4eba\u4e0d\u8001\u5b9e\u5462&#xff1f;<\/p>\n<p>\u5047\u8bbe\u7528\u6237\u8f93\u5165\u7684\u7528\u6237\u540d\u662f zhangsan\u2019 or 1&#061;1 #&#xff0c;\u5bc6\u7801\u5219\u968f\u610f\u7ed9\u4e86\u4e2a\u503c 111&#xff0c;\u90a3\u4e48\u6700\u7ec8\u751f\u6210\u7684 SQL\u8bed\u53e5\u53ef\u80fd\u5c31\u662f\u4e0b\u9762\u8fd9\u6837\u4e86&#xff1a;<\/p>\n<p>select * from user where username&#061;&#039;zhangsan&#039; or 1&#061;1 #&#039; and password&#061;&#039;123&#039;<\/p>\n<p>\u5b9e\u9645\u6267\u884c\u7684 SQL:<\/p>\n<p><span class=\"token keyword\">select<\/span> <span class=\"token operator\">*<\/span> <span class=\"token keyword\">from<\/span> <span class=\"token keyword\">user<\/span> <span class=\"token keyword\">where<\/span> username<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;zhangsan&#039;<\/span> <span class=\"token operator\">or<\/span> <span class=\"token number\">1<\/span><span class=\"token operator\">&#061;<\/span><span class=\"token number\">1<\/span><\/p>\n<p>\u5927\u5bb6\u77e5\u9053&#xff0c;# \u5728 SQL\u8bed\u53e5\u4e2d\u7684\u542b\u4e49\u662f\u6ce8\u91ca&#xff0c;#\u540e\u9762\u7684SQL\u5185\u5bb9\u662f\u4e0d\u6267\u884c\u7684\u3002\u6240\u4ee5\u8fd9\u4e2aSQL\u65e0\u8bba\u600e\u4e48\u6267\u884c&#xff0c;\u6700\u7ec8\u90fd\u4f1a\u8fd4\u56detrue\u3002\u8fd9\u5c31\u662f\u6240\u8c13\u7684SQL\u6ce8\u5165\u4e86\u3002<\/p>\n<p>\u533a\u522b<\/p>\n<p>1\u3001#{}\u4e3a\u9884\u7f16\u8bd1\u5904\u7406&#xff1b;${}\u4e3a\u5b57\u7b26\u4e32\u66ff\u6362\u3002<\/p>\n<p>2\u3001MyBatis\u5728\u5904\u7406#{}\u65f6&#xff0c;\u4f1a\u5c06sql\u4e2d\u7684#{}\u66ff\u6362\u6210&#xff1f;\u95ee\u53f7&#xff0c;\u8c03\u7528PreparedStatement\u7684set\u65b9\u6cd5\u6765\u8d4b\u503c\u3002<\/p>\n<p>3\u3001MyBatis\u5728\u5904\u7406${}\u65f6&#xff0c;\u5c31\u662f\u628a${}\u66ff\u6362\u4e3a\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<p>4\u3001\u4f7f\u7528\u7684#{}\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62SQL\u6ce8\u5165\u98ce\u9669&#xff0c;\u63d0\u9ad8\u7cfb\u7edf\u5b89\u5168\u6027\u3002<\/p>\n<p>\u5728 MyBatis \u4e2d&#xff0c;99% \u7684\u67e5\u8be2\u90fd\u5e94\u8be5\u4f7f\u7528 #{}\u3002\u6240\u6709\u7528\u6237\u8f93\u5165\u7684\u53c2\u6570\u90fd\u5fc5\u987b\u4f7f\u7528 #{} \u53ea\u6709\u5728\u6781\u5c11\u6570\u9700\u8981\u52a8\u6001 SQL \u7ed3\u6784&#xff08;\u8868\u540d\u3001\u6392\u5e8f\u5b57\u6bb5\u3001\u5217\u540d&#xff09;\u4e14\u53c2\u6570\u662f\u7a0b\u5e8f\u5df2\u77e5\u7684\u3001\u5b89\u5168\u7684\u503c\u7684\u60c5\u51b5\u4e0b&#xff0c;\u624d\u8003\u8651\u4f7f\u7528 ${}\u3002<\/p>\n<hr \/>\n<h3>\u52a8\u6001SQL<\/h3>\n<p>\u5047\u8bbe\u4f60\u6709\u4e00\u4e2a\u641c\u7d22\u9875\u9762&#xff0c;\u7528\u6237\u53ef\u4ee5\u6839\u636e\u4e0d\u540c\u7684\u6761\u4ef6\u6765\u641c\u7d22\u5546\u54c1&#xff0c;\u6bd4\u5982\u5546\u54c1\u540d\u3001\u4ef7\u683c\u8303\u56f4\u548c\u5206\u7c7b\u3002\u4f7f\u7528\u52a8\u6001SQL&#xff0c;\u4f60\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u7075\u6d3b\u7684\u67e5\u8be2\u8bed\u53e5&#xff0c;\u53ea\u5728\u7528\u6237\u63d0\u4f9b\u76f8\u5173\u6761\u4ef6\u65f6\u5305\u542b\u8fd9\u4e9b\u6761\u4ef6\u3002 \u5728MyBatis\u4e2d&#xff0c;\u4f60\u53ef\u4ee5\u4f7f\u7528&lt;if&gt;\u3001&lt;choose&gt;\u3001&lt;when&gt;\u3001&lt;otherwise&gt;\u7b49\u6807\u7b7e\u6765\u6784\u5efa\u52a8\u6001SQL\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50&#xff0c;\u5047\u8bbe\u4f60\u8981\u6839\u636e\u7528\u6237\u7684\u9009\u62e9\u6765\u52a8\u6001\u6784\u5efa\u67e5\u8be2\u8bed\u53e5&#xff1a;<\/p>\n<p><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>select<\/span> <span class=\"token attr-name\">id<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>searchProducts<span class=\"token punctuation\">&#034;<\/span><\/span> <span class=\"token attr-name\">resultType<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>Product<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n  SELECT * FROM products<br \/>\n  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>where<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>if<\/span> <span class=\"token attr-name\">test<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>productName !&#061; null<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n      AND name &#061; #{productName}<br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>if<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>if<\/span> <span class=\"token attr-name\">test<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>minPrice !&#061; null<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n      AND price &gt;&#061; #{minPrice}<br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>if<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>if<\/span> <span class=\"token attr-name\">test<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>maxPrice !&#061; null<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n      AND price &lt;&#061; #{maxPrice}<br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>if<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span>if<\/span> <span class=\"token attr-name\">test<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>category !&#061; null<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n      AND category &#061; #{category}<br \/>\n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>if<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>  <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>where<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><br \/>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;\/<\/span>select<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d&#xff0c;\u5982\u679c\u7528\u6237\u8f93\u5165\u4e86\u5546\u54c1\u540d\u3001\u4ef7\u683c\u8303\u56f4\u6216\u5206\u7c7b&#xff0c;\u5bf9\u5e94\u7684\u6761\u4ef6\u4f1a\u88ab\u5305\u542b\u5728\u67e5\u8be2\u8bed\u53e5\u4e2d\u3002\u5982\u679c\u7528\u6237\u6ca1\u6709\u63d0\u4f9b\u67d0\u4e2a\u6761\u4ef6&#xff0c;\u90a3\u4e48\u76f8\u5e94\u7684&lt;if&gt;\u5757\u5c31\u4f1a\u88ab\u5ffd\u7565&#xff0c;\u4ece\u800c\u6784\u5efa\u51fa\u9002\u5408\u7684\u67e5\u8be2\u8bed\u53e5\u3002<\/p>\n<hr \/>\n<h2>Spring<\/h2>\n<h3>IOC \u4e0e DI<\/h3>\n<ul>\n<li>Spring\u7684IOC&#xff0c;\u7ffb\u8bd1\u8fc7\u6765&#xff0c;\u53eb\u63a7\u5236\u53cd\u8f6c\u3002 \u6307\u7684\u662f\u5728Spring\u4e2d\u4f7f\u7528\u5de5\u5382\u6a21\u5f0f&#xff0c;\u4e3a\u6211\u4eec\u521b\u5efa\u4e86\u5bf9\u8c61&#xff0c;\u5e76\u4e14\u5c06\u8fd9\u4e9b\u5bf9\u8c61\u653e\u5728\u4e86\u4e00\u4e2a\u5bb9\u5668\u4e2d&#xff0c;\u6211\u4eec\u5728\u4f7f\u7528\u7684\u65f6\u5019&#xff0c;\u5c31\u4e0d\u7528\u6bcf\u6b21\u90fd\u53bbnew\u5bf9\u8c61\u4e86&#xff0c;\u76f4\u63a5\u8ba9\u5bb9\u5668\u4e3a\u6211\u4eec\u63d0\u4f9b\u8fd9\u4e9b\u5bf9\u8c61\u5c31\u53ef\u4ee5\u4e86\u3002 \u8fd9\u5c31\u662f\u63a7\u5236\u53cd\u8f6c\u7684\u601d\u60f3\u3002<\/li>\n<li>\u800cDI&#xff0c;\u7ffb\u8bd1\u8fc7\u6765&#xff0c;\u53eb\u4f9d\u8d56\u6ce8\u5165\u3002 \u90a3\u521a\u624d\u63d0\u5230&#xff0c;\u73b0\u5728\u5bf9\u8c61\u5df2\u7ecf\u4ea4\u7ed9\u5bb9\u5668\u7ba1\u7406\u4e86&#xff0c;\u90a3\u7a0b\u5e8f\u8fd0\u884c\u65f6&#xff0c;\u9700\u8981\u7528\u5230\u67d0\u4e2a\u5bf9\u8c61&#xff0c;\u6b64\u65f6\u5c31\u9700\u8981\u8ba9\u5bb9\u5668\u7ed9\u6211\u4eec\u63d0\u4f9b&#xff0c;\u8fd9\u4e2a\u8fc7\u7a0b\u5462&#xff0c;\u79f0\u4e4b\u4e3a\u4f9d\u8d56\u6ce8\u5165\u3002<\/li>\n<\/ul>\n<p>\u90a3\u5982\u4f55\u5c06\u4e00\u4e2a\u5bf9\u8c61&#xff0c;\u8bb2\u7ed9IOC\u5bb9\u5668\u7ba1\u7406\u5462&#xff1f;<\/p>\n<ul>\n<li>\u90a3\u73b0\u5728\u9879\u76ee\u5f00\u53d1&#xff0c;\u90fd\u662f\u57fa\u4e8eSpringboot\u6784\u5efa\u7684\u9879\u76ee&#xff0c;\u6240\u4ee5\u5462&#xff0c;\u58f0\u660ebean\u5bf9\u8c61&#xff0c;\u6211\u4eec\u53ea\u9700\u8981\u5728\u5bf9\u5e94\u7684\u7c7b\u4e0a\u52a0\u4e0a\u6ce8\u89e3\u5c31\u53ef\u4ee5\u4e86\u3002 \u6bd4\u5982&#xff1a;\n<ul>\n<li>\u5982\u679c\u662fcontroller\u5c42&#xff0c;\u76f4\u63a5\u5728\u7c7b\u4e0a\u52a0\u4e0a &#064;Controller \u6216 &#064;RestController \u6ce8\u89e3\u3002<\/li>\n<li>\u5982\u679c\u662fservice\u5c42&#xff0c;\u76f4\u63a5\u5728\u7c7b\u4e0a\u52a0\u4e0a &#064;Service \u6ce8\u89e3\u3002<\/li>\n<li>\u5982\u679c\u662fdao\u5c42&#xff0c;\u76f4\u63a5\u5728\u7c7b\u4e0a\u52a0\u4e0a &#064;Repository \u6ce8\u89e3\u3002\u5f53\u7136\u73b0\u5728\u57fa\u672c\u90fd\u662fMybatis \u6216 MybatisPlus&#xff0c;\u6240\u4ee5\u8fd9\u4e2a\u6ce8\u89e3\u5f88\u5c11\u7528\u4e86&#xff0c;\u90fd\u7528\u7684\u662f &#064;Mapper \u6ce8\u89e3\u3002<\/li>\n<li>\u5982\u679c\u662f\u4e00\u4e9b\u5176\u4ed6\u7684\u5de5\u5177\u7c7b\u3001\u914d\u7f6e\u7c7b\u554a&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 &#064;Component \u3001 &#064;Configuration \u6765\u58f0\u660e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u90a3\u5982\u4f55\u5b8c\u6210\u4f9d\u8d56\u6ce8\u5165\u64cd\u4f5c\u5462 ?<\/p>\n<p>\u4f9d\u8d56\u6ce8\u5165\u7684\u65b9\u5f0f\u6bd4\u8f83\u591a&#xff0c;\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u6784\u9020\u51fd\u6570\u6ce8\u5165 \u6216 \u6210\u5458\u53d8\u91cf\u8f93\u5165&#xff0c;\u4e5f\u662f\u4f7f\u7528\u5bf9\u5e94\u7684\u6ce8\u89e3\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>\u5e38\u7528\u7684\u6ce8\u89e3\u6709\u4e24\u4e2a&#xff1a; &#064;Autowired \u548c &#064;Resource \u6ce8\u89e3\u3002 \u90a3 &#064;Autowired \u9ed8\u8ba4\u662f\u6839\u636e\u7c7b\u578b\u6ce8\u5165&#xff0c;\u800c &#064;Resource \u6ce8\u89e3\u9ed8\u8ba4\u662f\u6839\u636e\u540d\u79f0\u6ce8\u5165\u3002<\/p>\n<hr \/>\n<h3>AOP<\/h3>\n<p>AOP\u9762\u5411\u5207\u9762\u7f16\u7a0b, \u5176\u5b9e\u5c31\u662f\u52a8\u6001\u5730\u5bf9\u7c7b\u65b9\u6cd5\u505a\u589e\u5f3a. \u53ef\u4ee5\u5728\u65b9\u6cd5\u6267 \u884c\u7684\u524d\u540e\u505a\u4e00\u4e9b\u4e8b\u60c5, \u80fd\u591f\u5c06\u901a\u7528\u64cd\u4f5c&#xff08;\u4f8b\u5982\u4e8b\u52a1\u5904\u7406\u3001\u65e5\u5fd7\u7ba1\u7406\u3001 \u6743\u9650\u63a7\u5236\u7b49&#xff09;\u5c01\u88c5\u8d77\u6765.<\/p>\n<p>\u4f60\u4eec\u9879\u76ee\u4e2d\u6709\u6ca1\u6709\u4f7f\u7528\u5230AOP&#xff1f;<\/p>\n<p>\u6211\u4eec\u5f53\u65f6\u5728\u540e\u53f0\u7ba1\u7406\u7cfb\u7edf\u4e2d&#xff0c;\u5c31\u662f\u4f7f\u7528aop\u6765\u8bb0\u5f55\u4e86\u7cfb\u7edf\u7684\u64cd\u4f5c\u65e5\u5fd7<\/p>\n<p>\u4e3b\u8981\u601d\u8def\u662f\u8fd9\u6837\u7684&#xff0c;\u4f7f\u7528aop\u4e2d\u7684\u73af\u7ed5\u901a\u77e5&#043;\u5207\u70b9\u8868\u8fbe\u5f0f&#xff0c;\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u5c31\u662f\u8981\u627e\u5230\u8981\u8bb0\u5f55\u65e5\u5fd7\u7684\u65b9\u6cd5&#xff0c;\u7136\u540e\u901a\u8fc7\u73af\u7ed5\u901a\u77e5\u7684\u53c2\u6570\u83b7\u53d6\u8bf7\u6c42\u65b9\u6cd5\u7684\u53c2\u6570&#xff0c;\u6bd4\u5982\u7c7b\u4fe1\u606f\u3001\u65b9\u6cd5\u4fe1\u606f\u3001\u6ce8\u89e3\u3001\u8bf7\u6c42\u65b9\u5f0f\u3001\u8bf7\u6c42\u53c2\u6570\u3001\u5f53 \u524d\u64cd\u4f5c\u4eba\u3001\u64cd\u4f5c\u65f6\u95f4\u3001\u8fd4\u56de\u503c\u7b49\u4fe1\u606f&#xff0c;\u5168\u90e8\u8bb0\u5f55\u4e0b\u6765&#xff0c;\u4fdd\u5b58\u5728\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<p>AOP\u7684\u5e95\u5c42\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff1f;<\/p>\n<p>AOP \u7684\u5e95\u5c42\u5b9e\u73b0\u662f\u52a8\u6001\u4ee3\u7406\u6280\u672f&#xff0c;Spring \u9ed8\u8ba4\u4f7f\u7528 JDK \u52a8\u6001\u4ee3\u7406&#xff08;\u5f53\u76ee\u6807\u7c7b\u5b9e\u73b0\u63a5\u53e3\u65f6&#xff09;&#xff0c;\u5f53\u76ee\u6807\u7c7b\u6ca1\u6709\u5b9e\u73b0\u63a5\u53e3\u65f6\u81ea\u52a8\u5207\u6362\u5230 CGLIB \u52a8\u6001\u4ee3\u7406\u3002 JDK \u52a8\u6001\u4ee3\u7406\u57fa\u4e8e\u63a5\u53e3&#xff0c;\u6027\u80fd\u66f4\u597d&#xff0c;\u662f Spring \u7684\u9ed8\u8ba4\u9009\u62e9&#xff1b;CGLIB \u52a8\u6001\u4ee3\u7406\u57fa\u4e8e\u7c7b\u7684\u7ee7\u627f&#xff0c;\u5f53\u76ee\u6807\u7c7b\u6ca1\u6709\u5b9e\u73b0\u63a5\u53e3\u65f6\u4f7f\u7528\u3002<\/p>\n<hr \/>\n<h3>Spring\u5bb9\u5668\u4e2d\u7684\u5355\u4f8bbean\u662f\u7ebf\u7a0b\u5b89\u5168\u7684\u5417?<\/h3>\n<p>\u201cSpring \u5bb9\u5668\u4e2d\u7684\u5355\u4f8b Bean \u5e76\u4e0d\u81ea\u52a8\u662f\u7ebf\u7a0b\u5b89\u5168\u7684&#xff01;\u201d \u5355\u4f8b\u6307\u7684\u662f\u5bb9\u5668\u4e2d\u53ea\u5b58\u5728\u4e00\u4e2a Bean \u5b9e\u4f8b&#xff0c;\u4f46\u8fd9\u4e2a\u5b9e\u4f8b\u53ef\u80fd\u88ab\u591a\u4e2a\u7ebf\u7a0b\u540c\u65f6\u8bbf\u95ee&#xff0c;\u5982\u679c Bean \u6709\u53ef\u53d8\u72b6\u6001&#xff08;\u5b9e\u4f8b\u53d8\u91cf&#xff09;&#xff0c;\u5219\u5b58\u5728\u7ebf\u7a0b\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<p>\u6bd4\u5982&#xff1a;<\/p>\n<p><span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">CounterService<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">private<\/span> <span class=\"token keyword\">int<\/span> count <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u53ef\u53d8\u72b6\u6001<\/span><\/p>\n<p>    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">increment<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        count<span class=\"token operator\">&#043;&#043;<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u975e\u7ebf\u7a0b\u5b89\u5168\u64cd\u4f5c<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u4e3a\u4e86\u786e\u4fdd\u5355\u4f8bBean\u7684\u7ebf\u7a0b\u5b89\u5168\u6027&#xff0c;\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\u65e0\u72b6\u6001 Bean&#xff0c;\u8ba9 Bean \u4e0d\u5305\u542b\u4efb\u4f55\u72b6\u6001&#xff08;\u65e0\u5b9e\u4f8b\u53d8\u91cf&#xff09;&#xff0c;\u6240\u6709\u64cd\u4f5c\u53ea\u4f9d\u8d56\u4e8e\u8f93\u5165\u53c2\u6570\u3002<\/li>\n<li>\u4f7f\u7528\u7ebf\u7a0b\u5b89\u5168\u7684\u96c6\u5408&#xff0c;\u5982\u679c\u5fc5\u987b\u7ef4\u62a4\u72b6\u6001&#xff0c;\u4f7f\u7528\u7ebf\u7a0b\u5b89\u5168\u7684\u96c6\u5408\u7c7b\u3002<\/li>\n<li>\u4f7f\u7528\u540c\u6b65\u673a\u5236&#xff08;synchronized&#xff09;&#xff0c;\u5728\u5173\u952e\u65b9\u6cd5\u6216\u4ee3\u7801\u5757\u4e0a\u4f7f\u7528 synchronized\u3002<\/li>\n<li>\u4f7f\u7528 ThreadLocal&#xff08;\u6bcf\u4e2a\u7ebf\u7a0b\u72ec\u7acb\u72b6\u6001&#xff09;&#xff0c;\u4e3a\u6bcf\u4e2a\u7ebf\u7a0b\u521b\u5efa\u72ec\u7acb\u7684\u53d8\u91cf\u526f\u672c\u3002<\/li>\n<li>\u4f7f\u7528\u539f\u578b\u4f5c\u7528\u57df&#xff08;&#064;Scope(\u201cprototype\u201d)&#xff09;&#xff0c;\u5373\u6bcf\u6b21\u4f7f\u7528\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b9e\u4f8b<\/li>\n<\/ul>\n<hr \/>\n<h3>Spring Bean\u7684\u4f5c\u7528\u57df\u5982\u4f55\u8bbe\u7f6e&#xff0c;\u5e38\u89c1\u7684\u53d6\u503c\u6709\u54ea\u4e9b &#xff1f;<\/h3>\n<p>Spring Bean\u7684\u4f5c\u7528\u57df\u53ef\u4ee5\u901a\u8fc7 &#064;Scope \u6ce8\u89e3\u6765\u8bbe\u7f6e\u3002\u5e38\u89c1\u7684\u53d6\u503c\u5982\u4e0b&#xff1a;<\/p>\n<ul>\n<li>singleton &#xff1a;\u8fd9\u79cdbean\u8303\u56f4\u662f\u9ed8\u8ba4\u7684&#xff0c;\u8fd9\u79cd\u8303\u56f4\u786e\u4fdd\u4e0d\u7ba1\u63a5\u53d7\u5230\u591a\u5c11\u4e2a\u8bf7\u6c42&#xff0c;\u6bcf\u4e2a\u5bb9\u5668\u4e2d\u540c\u4e00\u4e2a\u540d\u79f0\u7684bean\u53ea\u6709\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u4e5f\u5c31\u662f\u5355\u4f8b\u7684<\/li>\n<li>prototype &#xff1a;\u8fd9\u79cd\u8303\u56f4&#xff0c;\u8868\u793a\u975e\u5355\u4f8b\u7684\u3002\u4e5f\u5c31\u662f\u8bf4\u6bcf\u4e00\u6b21\u7528\u5230\u7684bean\u90fd\u662f\u4e00\u4e2a\u65b0\u7684 \u3002<\/li>\n<li>request &#xff1a;\u540c\u4e00\u4e2a\u8bf7\u6c42&#xff0c;\u4f7f\u7528\u7684\u662f\u540c\u4e00\u4e2abean\u3002\u4f1a\u4e3a\u6bcf\u4e00\u4e2a\u6765\u81ea\u5ba2\u6237\u7aef\u7684\u8bf7\u6c42\u90fd\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5728\u8bf7\u6c42\u5b8c\u6210\u4ee5\u540e&#xff0c; bean\u4f1a\u5931\u6548\u5e76\u88ab\u5783\u573e\u56de \u6536\u5668\u56de\u6536 \u3002<\/li>\n<li>session&#xff1a;\u4e0erequest \u8bf7\u6c42\u8303\u56f4\u7c7b\u4f3c&#xff0c;\u786e\u4fdd\u6bcf\u4e2asession\u4f1a\u8bdd\u8303\u56f4\u5185&#xff0c;\u662f\u540c\u4e00\u4e2a\u5b9e\u4f8b&#xff0c;\u5728session\u8fc7\u671f\u540e&#xff0c; bean\u4f1a\u968f\u4e4b\u5931\u6548<\/li>\n<\/ul>\n<p>\u867d\u7136&#xff0c;bean\u4f5c\u7528\u57df\u53ef\u4ee5\u8bbe\u7f6e\u8fd9\u4e9b\u503c&#xff0c;\u4f46\u662f\u5728\u9879\u76ee\u5f00\u53d1\u4e2d&#xff0c;\u7edd\u5927\u90e8\u5206\u7684bean\u90fd\u4e0d\u4f1a\u6dfb\u52a0\u8fd9\u4e2a &#064;Scope \u6ce8\u89e3&#xff0c;\u4e5f\u5c31\u662f\u8bf4\u9ed8\u8ba4\u90fd\u662f\u7528\u7684\u662f\u5355\u4f8b\u7684 bean\u3002<\/p>\n<hr \/>\n<h3>Spring\u5bb9\u5668\u7684bean\u4ec0\u4e48\u65f6\u5019\u521d\u59cb\u5316\u7684?<\/h3>\n<ul>\n<li>\u5982\u679c\u662f\u5355\u4f8b\u7684bean&#xff0c;\u9ed8\u8ba4\u662fSpring\u5bb9\u5668\u542f\u52a8\u7684\u65f6\u5019&#xff0c;\u5c31\u5b8c\u6210bean\u7684\u521d\u59cb\u5316\u64cd\u4f5c&#xff0c;\u90a3\u8fd9\u662f\u9ed8\u8ba4\u60c5\u51b5&#xff0c;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7 &#064;Lazy \u6ce8\u89e3\u6765\u5ef6\u8fdfbean \u7684\u521d\u59cb\u5316&#xff0c;\u5ef6\u8fdf\u5230\u7b2c\u4e00\u6b21\u4f7f\u7528\u7684\u65f6\u5019\u3002<\/li>\n<li>\u800c\u5982\u679c\u662f\u975e\u5355\u4f8b\u7684bean&#xff08;\u4e5f\u5c31\u662fprototype&#xff09;&#xff0c;\u5219\u662f\u5728\u6bcf\u6b21\u4f7f\u7528\u8fd9\u4e2abean\u7684\u65f6\u5019&#xff0c;\u90fd\u4f1a\u91cd\u65b0\u5b9e\u4f8b\u5316\u4e00\u4e2a\u65b0\u7684bean\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>Spring\u4e2d\u7684\u4e8b\u52a1\u662f\u5982\u4f55\u5b9e\u73b0\u7684&#xff1f;<\/h3>\n<p>spring\u5b9e\u73b0\u7684\u4e8b\u52a1\u672c\u8d28\u5c31\u662faop\u5b8c\u6210&#xff0c;\u5bf9\u65b9\u6cd5\u524d\u540e\u8fdb\u884c\u62e6\u622a&#xff0c;\u5728\u6267\u884c\u65b9\u6cd5\u4e4b\u524d\u5f00\u542f\u4e8b\u52a1&#xff0c;\u5728\u6267\u884c\u5b8c\u76ee\u6807\u65b9\u6cd5\u4e4b\u540e\u6839\u636e\u6267\u884c\u60c5\u51b5\u63d0\u4ea4\u6216\u8005\u56de\u6eda\u4e8b\u52a1\u3002 \u800c\u5982\u679c\u6211\u4eec\u8fdb\u884c\u9879\u76ee\u5f00\u53d1&#xff0c;\u4e0d\u5b58\u5728\u5206\u5e03\u5f0f\u4e8b\u52a1\u95ee\u9898&#xff0c;\u6211\u4eec\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Spring\u63d0\u4f9b\u7684 &#064;Transactional \u6ce8\u89e3\u6765\u63a7\u5236\u4e8b\u52a1\u5373\u53ef\u3002<\/p>\n<p>**\u5728\u5f00\u53d1\u4e2d&#xff0c;\u6709\u6ca1\u6709\u9047\u5230\u4e8b\u52a1\u5931\u6548\u7684\u573a\u666f? **<\/p>\n<ul>\n<li>\n<p>\u7b2c\u4e00\u4e2a&#xff0c;\u5982\u679c\u4e1a\u52a1\u65b9\u6cd5\u4e0atry\u3001catch\u5904\u7406&#xff0c;\u81ea\u5df1\u5904\u7406\u4e86\u5f02\u5e38&#xff0c;\u6ca1\u6709\u629b\u51fa&#xff0c;\u5c31\u4f1a\u5bfc\u81f4\u4e8b\u52a1\u5931\u6548&#xff0c;\u6240\u4ee5\u4e00\u822c\u5904\u7406\u4e86\u5f02\u5e38\u4ee5\u540e&#xff0c;\u522b\u5fd8\u4e86\u629b\u51fa\u53bb\u5c31\u884c\u3002<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">UserService<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Transactional<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">saveUser<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">User<\/span> user<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u4e1a\u52a1\u903b\u8f91<\/span><br \/>\n            userRepository<span class=\"token punctuation\">.<\/span><span class=\"token function\">save<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u6a21\u62df\u5f02\u5e38<\/span><br \/>\n            <span class=\"token keyword\">int<\/span> i <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span> <span class=\"token operator\">\/<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Exception<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u5904\u7406\u5f02\u5e38&#xff0c;\u4f46\u6ca1\u6709\u91cd\u65b0\u629b\u51fa<\/span><br \/>\n            <span class=\"token class-name\">System<\/span><span class=\"token punctuation\">.<\/span>out<span class=\"token punctuation\">.<\/span><span class=\"token function\">println<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u5f02\u5e38\u5df2\u5904\u7406: &#034;<\/span> <span class=\"token operator\">&#043;<\/span> e<span class=\"token punctuation\">.<\/span><span class=\"token function\">getMessage<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token comment\">\/\/ \u4e8b\u52a1\u4e0d\u4f1a\u56de\u6eda&#xff01;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u539f\u56e0&#xff1a;\u4e8b\u52a1\u901a\u77e5\u53ea\u6709\u6355\u6349\u5230\u4e86\u76ee\u6807\u629b\u51fa\u7684\u5f02\u5e38&#xff0c;\u624d\u80fd\u8fdb\u884c\u540e\u7eed\u7684\u56de\u6eda\u5904\u7406&#xff0c;\u5982\u679c\u76ee\u6807\u81ea\u5df1\u5904\u7406\u4e86\u5f02\u5e38&#xff0c;\u4e8b\u52a1\u901a\u77e5\u65e0\u6cd5\u77e5\u6089&#xff1b;<\/p>\n<p>\u89e3\u51b3&#xff1a;\u5728catch\u5757\u4e2d\u6dfb\u52a0throw e\u629b\u51fa;<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e8c\u4e2a&#xff0c;\u5982\u679c\u65b9\u6cd5\u629b\u51fa\u68c0\u67e5\u5f02\u5e38&#xff0c;\u5982\u679c\u62a5\u9519\u4e5f\u4f1a\u5bfc\u81f4\u4e8b\u52a1\u5931\u6548&#xff0c;\u56e0\u4e3a\u9ed8\u8ba4spring\u4e8b\u52a1\u7ba1\u7406\u53ea\u4f1a\u9488\u5bf9\u4e8eRuntimeException\u8fdb\u884c\u56de\u6eda\u3002\u90a3\u8fd9\u4e2a\u5462&#xff0c;\u5c31\u53ef\u4ee5\u5728spring\u4e8b\u52a1\u7684\u6ce8\u89e3\u4e0a&#xff0c;\u5c31\u662f&#064;Transactional\u4e0a\u914d\u7f6erollbackFor\u5c5e\u6027\u4e3aException.class&#xff0c;\u8fd9\u6837\u522b\u7ba1\u662f\u4ec0\u4e48\u5f02\u5e38&#xff0c;\u90fd\u4f1a\u56de\u6eda\u4e8b\u52a1\u3002<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">UserService<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Transactional<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">saveUser<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">User<\/span> user<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">throws<\/span> <span class=\"token class-name\">Exception<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        userRepository<span class=\"token punctuation\">.<\/span><span class=\"token function\">save<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Exception<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;\u624b\u52a8\u629b\u51fa\u68c0\u67e5\u5f02\u5e38&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span> <span class=\"token comment\">\/\/ \u68c0\u67e5\u5f02\u5e38<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u539f\u56e0&#xff1a;Spring\u9ed8\u8ba4\u53ea\u4f1a\u56de\u6eda\u975e\u68c0\u67e5\u5f02\u5e38&#xff1b;<\/p>\n<p>\u89e3\u51b3&#xff1a; &#064;Transactional(rollbackFor &#061; Exception.class) \/\/ \u5173\u952e&#xff1a;\u6307\u5b9a\u56de\u6eda\u6240\u6709\u5f02\u5e38<\/p>\n<\/li>\n<li>\n<p>\u7b2c\u4e09\u4e2a&#xff0c;\u662f\u6211\u65e9\u671f\u5f00\u53d1\u4e2d\u9047\u5230\u7684\u4e00\u4e2a&#xff0c;\u5982\u679c\u4e1a\u52a1\u65b9\u6cd5\u4e0a\u4e0d\u662fpublic\u4fee\u9970\u7684&#xff0c;\u4e5f\u4f1a\u5bfc\u81f4\u4e8b\u52a1\u5931\u6548\u3002<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Service<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">UserService<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Transactional<\/span><br \/>\n    <span class=\"token keyword\">void<\/span> <span class=\"token function\">saveUser<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">User<\/span> user<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span> <span class=\"token comment\">\/\/ \u95ee\u9898&#xff1a;\u4e0d\u662fpublic\u65b9\u6cd5<\/span><br \/>\n        userRepository<span class=\"token punctuation\">.<\/span><span class=\"token function\">save<\/span><span class=\"token punctuation\">(<\/span>user<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u539f\u56e0&#xff1a;Spring\u4e3a\u65b9\u6cd5\u521b\u5efa\u4ee3\u7406\u3001\u6dfb\u52a0\u4e8b\u52a1\u901a\u77e5&#xff0c;\u524d\u63d0\u6761\u4ef6\u90fd\u662f\u8be5\u65b9\u6cd5\u662fpublic\u7684&#xff1b;<\/p>\n<p>\u89e3\u51b3&#xff1a;\u6539\u4e3apublic&#xff1b;<\/p>\n<\/li>\n<\/ul>\n<p>\u4ec0\u4e48\u662f\u4e8b\u52a1\u7684\u4f20\u64ad\u884c\u4e3a ?<\/p>\n<p>Spring\u7684\u4e8b\u52a1\u4f20\u64ad\u884c\u4e3a&#xff0c;\u6307\u7684\u662f\u4e24\u4e2a\u88ab\u4e8b\u52a1\u63a7\u5236\u7684\u65b9\u6cd5&#xff0c;\u76f8\u4e92\u8c03\u7528\u7684\u8fc7\u7a0b\u4e2d&#xff0c;\u5230\u5e95\u662f\u52a0\u5165\u5230\u5df2\u5b58\u5728\u7684\u4e8b\u52a1&#xff0c;\u8fd8\u662f\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1&#xff0c;\u63a7\u5236\u7684\u662f \u8fd9\u4e2a\u4e8b\u513f\u3002 \u6211\u4eec\u8bbe\u7f6e\u4e8b\u52a1\u7684\u4f20\u64ad\u884c\u4e3a&#xff0c;\u53ef\u4ee5\u901a\u8fc7 &#064;Transactional \u6ce8\u89e3\u7684propagation\u5c5e\u6027\u6765\u8bbe\u7f6e&#xff0c;\u53ef\u53d6\u503c\u6709\u5f88\u591a\u554a&#xff0c;\u4f46\u662f\u5e38\u89c1\u7684\u5c31\u53ea\u6709\u4e24\u4e2a&#xff1a;<\/p>\n<ul>\n<li>REQUIRED&#xff1a;\u4e5f\u662f\u9ed8\u8ba4\u503c&#xff0c;\u8868\u793a\u5982\u679c\u6ca1\u6709\u4e8b\u52a1&#xff0c;\u5c31\u65b0\u5efa\u4e00\u4e2a\u4e8b\u52a1&#xff0c;\u5982\u679c\u6709\u4e8b\u52a1&#xff0c;\u5c31\u52a0\u5165\u5230\u5df2\u5b58\u5728\u7684\u4e8b\u52a1\u4e2d\u3002<\/li>\n<li>REQIRES_NEW&#xff1a;\u8868\u793a\u9700\u8981\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1&#xff0c;\u65e0\u8bba\u5f53\u524d\u73af\u5883\u662f\u5426\u5b58\u5728\u4e8b\u52a1&#xff0c;\u90fd\u4f1a\u5f00\u542f\u4e00\u4e2a\u65b0\u7684\u4e8b\u52a1\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>Spring\u6846\u67b6\u4e2d\u7684\u5e38\u7528\u6ce8\u89e3<\/h3>\n<ul>\n<li>\u7b2c\u4e00\u7c7b\u662f&#xff1a;\u58f0\u660ebean&#xff0c;\u6709&#064;Component\u3001&#064;Service\u3001&#064;Repository\u3001&#064;Controller<\/li>\n<li>\u7b2c\u4e8c\u7c7b\u662f&#xff1a;\u4f9d\u8d56\u6ce8\u5165\u76f8\u5173\u7684&#xff0c;\u6709&#064;Autowired\u3001&#064;Qualifier\u3001&#064;Resourse<\/li>\n<li>\u7b2c\u4e09\u7c7b\u662f&#xff1a;\u8bbe\u7f6e\u4f5c\u7528\u57df &#064;Scope<\/li>\n<li>\u7b2c\u56db\u7c7b\u662f&#xff1a;spring\u914d\u7f6e\u76f8\u5173\u7684&#xff0c;\u6bd4\u5982&#064;Configuration&#xff0c;&#064;ComponentScan \u548c &#064;Bean<\/li>\n<li>\u7b2c\u4e94\u7c7b\u662f&#xff1a;\u8ddfaop\u76f8\u5173\u505a\u589e\u5f3a\u7684\u6ce8\u89e3 &#064;Aspect&#xff0c;&#064;Before&#xff0c;&#064;After&#xff0c;&#064;Around&#xff0c;&#064;AfterReturning&#xff0c;&#064;AfterThrowing&#xff0c;&#064;Pointcut<\/li>\n<\/ul>\n<hr \/>\n<h2>SpringMVC<\/h2>\n<h3>MVC\u5206\u5c42\u662f\u4ec0\u4e48<\/h3>\n<p>MVC\u5168\u540d\u662fModel View Controller, \u6a21\u578b(model), \u89c6\u56fe(view), \u63a7\u5236 \u5668(controller). \u5b83\u662f\u4e00\u79cd\u8f6f\u4ef6\u8bbe\u8ba1\u89c4\u8303&#xff0c;\u53ef\u4ee5\u7528\u4e00\u79cd\u4e1a\u52a1\u903b\u8f91\u3001\u6570 \u636e\u3001\u754c\u9762\u663e\u793a\u5206\u79bb\u7684\u65b9\u6cd5\u7ec4\u7ec7\u4ee3\u7801.<\/p>\n<ul>\n<li>\u89c6\u56fe&#xff08;view): \u4e3a\u7528\u6237\u63d0\u4f9b\u4f7f\u7528\u754c\u9762&#xff0c;\u4e0e\u7528\u6237\u76f4\u63a5\u8fdb\u884c\u4ea4\u4e92\u3002<\/li>\n<li>\u6a21\u578b&#xff08;model): \u6a21\u578b\u5206\u4e3a\u4e24\u7c7b, \u4e00\u7c7b\u79f0\u4e3a\u6570\u636e\u627f\u8f7dBean, \u4e00\u7c7b\u79f0\u4e3a \u4e1a\u52a1\u5904\u7406Bean\u3002\u6240\u8c13\u6570\u636e\u627f\u8f7dBean\u662f\u6307\u5b9e\u4f53\u7c7b&#xff08;\u5982&#xff1a;User\u7c7b&#xff09;, \u4e13\u95e8\u4e3a\u7528\u6237\u627f\u8f7d\u4e1a\u52a1\u6570\u636e\u7684&#xff1b;\u4e1a\u52a1\u5904\u7406Bean\u5219\u662f\u6307Service\u6216 Dao\u5bf9\u8c61&#xff0c;\u4e13\u95e8\u7528\u4e8e\u5904\u7406\u7528\u6237\u63d0\u4ea4\u8bf7\u6c42\u7684\u3002<\/li>\n<li>\u63a7\u5236\u5668&#xff08;controller): \u7528\u4e8e\u5c06\u7528\u6237\u8bf7\u6c42\u8f6c\u53d1\u7ed9\u76f8\u5e94\u7684Model\u8fdb\u884c\u5904 \u7406&#xff0c;\u5e76\u6839\u636eModel\u7684\u8ba1\u7b97\u7ed3\u679c\u5411\u7528\u6237\u63d0\u4f9b\u76f8\u5e94\u54cd\u5e94\u3002\u5b83\u4f7f\u89c6\u56fe\u4e0e\u6a21\u578b\u5206\u79bb\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>SpringMVC\u7684\u6267\u884c\u6d41\u7a0b<\/h3>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101726-697890b60693b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<ul>\n<li>\u5ba2\u6237\u7aef\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9\u524d\u7aef\u63a7\u5236\u5668DispatcherServlet&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u8c03\u5ea6\u4e2d\u5fc3<\/li>\n<li>\u524d\u7aef\u63a7\u5236\u5668\u5c06\u8bf7\u6c42\u53d1\u9001\u7ed9\u5904\u7406\u5668\u6620\u5c04\u5668HandlerMapping&#xff0c;\u5904\u7406\u5668\u6620\u5c04\u5668\u6839\u636e\u8def\u5f84\u627e\u5230\u65b9\u6cd5\u7684\u6267\u884c\u94fe&#xff0c;\u8fd4\u56de\u7ed9\u524d\u7aef\u63a7\u5236\u5668\u3002<\/li>\n<li>\u524d\u7aef\u63a7\u5236\u5668\u5c06\u65b9\u6cd5\u7684\u6267\u884c\u94fe\u53d1\u9001\u7ed9\u5904\u7406\u5668\u9002\u914d\u5668HandlerAdapter&#xff0c;\u5904\u7406\u5668\u9002\u914d\u5668\u6839\u636e\u65b9\u6cd5\u7c7b\u578b\u627e\u5230\u5bf9\u5e94\u7684\u5904\u7406Handler(\u8fd9\u4e2a Handler\u6307\u7684\u662f\u6211\u4eec\u81ea\u5df1\u5199\u7684Controller&#xff09;<\/li>\n<li>Handler\u5b8c\u6210\u5bf9\u7528\u6237\u8bf7\u6c42\u7684\u5904\u7406\u540e&#xff0c;\u4f1a\u8fd4\u56de\u4e00\u4e2aModelAndView \u5bf9\u8c61\u7ed9\u524d\u7aef\u63a7\u5236\u5668\u3002<\/li>\n<li>\u524d\u7aef\u63a7\u5236\u5668DispatcherServlet\u5c06\u7ed3\u679c\u53d1\u9001\u7ed9\u89c6\u56fe\u89e3\u6790\u5668ViewReslover&#xff0c;\u89c6\u56fe\u89e3\u6790\u5668\u627e\u5230\u89c6\u56fe\u6587\u4ef6\u4f4d\u7f6e\u3002<\/li>\n<li>\u89c6\u56fe\u6e32\u67d3\u6570\u636e\u5e76\u5c06\u7ed3\u679c\u663e\u793a\u5230\u5ba2\u6237\u7aef\u3002<\/li>\n<\/ul>\n<p>\u73b0\u5728\u4e3b\u6d41\u7684\u5f00\u53d1\u65b9\u5f0f\u662f\u524d\u540e\u7aef\u5206\u79bb&#xff0c;\u540e\u7aef\u4e0d\u4f1a\u5728\u7ba1View\u4e86(\u4e0d\u518d\u8d1f\u8d23 \u6e32\u67d3\u9875\u9762). View\u7531\u524d\u7aef\u6846\u67b6&#xff08;Vue,React\u7b49&#xff09;\u6765\u5904\u7406. \u540e\u7aef\u53ea\u4f1a\u7ed9\u524d \u7aef\u8fd4\u56deJSON\u6570\u636e. \u524d\u7aef\u6e32\u67d3\u6570\u636e\u5230View\u4e0a<\/p>\n<p>Handler\u5b8c\u6210\u5bf9\u7528\u6237\u8bf7\u6c42\u7684\u5904\u7406\u540e&#xff0c;\u4f1a\u5c06\u8fd4\u56de\u8f6c\u4e3aJSON\u7ed9 \u524d\u7aef\u63a7\u5236\u5668<\/p>\n<p>\u524d\u7aef\u63a7\u5236\u5668\u628aJSON\u7ed9\u524d\u7aef, \u524d\u7aef\u6846\u67b6&#xff08;Vue,React\u7b49&#xff09;\u6765\u6e32\u67d3\u6570\u636e.<\/p>\n<hr \/>\n<h3>SpringMVC\u5e38\u89c1\u7684\u6ce8\u89e3\u6709\u54ea\u4e9b&#xff1f;<\/h3>\n<p>\u55ef&#xff0c;\u8fd9\u4e2a\u4e5f\u5f88\u591a\u7684 \u3002\u6709&#064;RequestMapping&#xff1a;\u7528\u4e8e\u6620\u5c04\u8bf7\u6c42\u8def\u5f84&#xff1b; &#064;RequestBody&#xff1a;\u6ce8\u89e3\u5b9e\u73b0\u63a5\u6536http\u8bf7\u6c42\u7684json\u6570\u636e&#xff0c;\u5c06json\u8f6c\u6362\u4e3ajava\u5bf9\u8c61&#xff1b; &#064;RequestParam&#xff1a;\u6307\u5b9a\u8bf7\u6c42\u53c2\u6570\u7684\u540d\u79f0&#xff1b; &#064;PathViriable&#xff1a;\u4ece\u8bf7\u6c42\u8def\u5f84\u4e0b\u4e2d\u83b7\u53d6\u8bf7\u6c42\u53c2\u6570(\/user\/{id})&#xff0c;\u4f20\u9012\u7ed9\u65b9\u6cd5\u7684\u5f62\u5f0f\u53c2\u6570&#xff1b;&#064;ResponseBody&#xff1a;\u6ce8\u89e3\u5b9e\u73b0\u5c06controller\u65b9\u6cd5\u8fd4\u56de\u5bf9\u8c61\u8f6c\u5316\u4e3ajson\u5bf9\u8c61\u54cd\u5e94\u7ed9\u5ba2\u6237\u7aef\u3002&#064;RequestHeader&#xff1a;\u83b7\u53d6\u6307\u5b9a\u7684\u8bf7\u6c42\u5934\u6570\u636e&#xff0c;\u8fd8\u6709\u50cf&#064;PostMapping\u3001&#064;GetMapping\u8fd9\u4e9b\u3002<\/p>\n<hr \/>\n<h3>SpringMVC\u7684\u62e6\u622a\u5668<\/h3>\n<p>\u62e6\u622a\u5668\u7684\u5e94\u7528\u573a\u666f\u8fd8\u662f\u5f88\u591a\u7684&#xff0c;\u6bd4\u5982\u5728\u9879\u76ee\u4e2d&#xff0c;\u6211\u4eec\u57fa\u4e8e\u62e6\u622a\u5668\u5b9e\u73b0**\u6743\u9650\u9a8c\u8bc1&#xff08;\u767b\u5f55\u68c0\u67e5&#xff09;\u3001\u8bf7\u6c42\u65e5\u5fd7\u8bb0\u5f55&#xff08;\u53ef\u83b7\u53d6\u8bf7\u6c42\u53c2\u6570\u3001\u6267\u884c\u65f6\u95f4&#xff09;**\u7b49\u529f\u80fd\u3002 \u5728SpringBoot\u9879\u76ee\u62e6\u622a\u5668\u7684\u4f7f\u7528\u5206\u4e3a\u4e24\u6b65\u8fdb\u884c&#xff1a;<\/p>\n<ul>\n<li>\u7b2c\u4e00\u6b65\u5462&#xff0c;\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u7c7b\u5b9e\u73b0HandlerInterceptor\u63a5\u53e3&#xff0c;\u7136\u540e\u518d\u5b9e\u73b0\u63a5\u53e3\u4e2d\u7684\u65b9\u6cd5&#xff0c;\u6bd4\u5982&#xff1a;preHandle\u3001postHandle\u3001afterCompletion\u3002<\/li>\n<li>\u7b2c\u4e8c\u6b65\u5462&#xff0c;\u5c31\u662f\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u914d\u7f6e\u7c7b&#xff0c;\u7136\u540e\u5b9e\u73b0WebMvcConfigure&#xff0c;\u7136\u540e\u5728\u8fd9\u4e2a\u914d\u7f6e\u7c7b\u4e2d\u914d\u7f6e\u62e6\u622a\u5668&#xff0c;\u6307\u5b9a\u62e6\u622a\u5668\u7684\u62e6\u622a\u8def\u5f84\u3001\u6392\u9664\u54ea\u4e9b\u8def\u5f84 \u7b49\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u4f60\u8bf4\u7684\u8fd9\u4e9b\u4e2a\u529f\u80fd&#xff0c;\u8fc7\u6ee4\u5668\u597d\u50cf\u4e5f\u80fd\u5e72&#xff0c;\u90a3\u62e6\u622a\u5668Interceptor \u4e0e \u8fc7\u6ee4\u5668Filter\u6709\u4ec0\u4e48\u533a\u522b?<\/p>\n<ul>\n<li>\u63a5\u53e3\u89c4\u8303\u4e0d\u540c&#xff1a;\u8fc7\u6ee4\u5668\u9700\u8981\u5b9e\u73b0Filter\u63a5\u53e3&#xff0c;\u800c\u62e6\u622a\u5668\u9700\u8981\u5b9e\u73b0HandlerInterceptor\u63a5\u53e3\u3002<\/li>\n<li>\u62e6\u622a\u8303\u56f4\u4e0d\u540c&#xff1a;Filter \u662f Servlet \u5bb9\u5668\u7684\u8fc7\u6ee4\u673a\u5236&#xff0c;\u4f1a\u62e6\u622aweb\u670d\u52a1\u5668\u4e2d\u7684\u6240\u6709\u8d44\u6e90&#xff0c;\u800cInterceptor \u662f Spring MVC \u7684\u62e6\u622a\u673a\u5236&#xff0c;\u53ea\u4f1a\u62e6\u622aSpring\u73af\u5883\u7684\u8d44\u6e90&#xff0c;\u4e3b\u8981\u5c31\u662fController\u3002<\/li>\n<li>\u6267\u884c\u987a\u5e8f\u4e0d\u540c&#xff1a;\u9996\u5148\u6267\u884c\u8fc7\u6ee4\u5668Filter&#xff0c;\u7136\u540e\u518d\u6267\u884c\u62e6\u622a\u5668Interceptor\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>SpringMVC\u600e\u4e48\u5904\u7406\u5f02\u5e38?<\/h3>\n<p>SpringMVC\u7684\u5f02\u5e38\u5904\u7406&#xff0c;\u5c31\u6bd4\u8f83\u7b80\u5355\u4e86&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Spring MVC\u4e2d\u7684\u5168\u5c40\u5f02\u5e38\u5904\u7406\u5668\u5bf9\u5f02\u5e38\u8fdb\u884c\u7edf\u4e00\u5904\u7406&#xff0c;\u6b64\u65f6\u5728\u6211\u4eec\u7684\u4e09\u5c42\u67b6\u6784\u4e2d&#xff0c;\u90fd\u4e0d \u9700\u8981\u5904\u7406\u5f02\u5e38\u4e86&#xff0c;\u5982\u679c\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u5f02\u5e38&#xff0c;\u6700\u7ec8\u4f1a\u88ab\u5168\u5c40\u5f02\u5e38\u5904\u7406\u5668\u6355\u83b7&#xff0c;\u7136\u540e\u8fd4\u56de\u7edf\u4e00\u7684\u9519\u8bef\u4fe1\u606f\u3002 \u5f00\u53d1\u4e00\u4e2a\u5168\u5c40\u5f02\u5e38\u5904\u7406\u5668\u9700\u8981\u4f7f\u7528\u5230\u4e24\u4e2a\u6ce8\u89e3&#xff1a;&#064;RestControllerAdvice \u3001&#064;ExceptionHandler\u3002<\/p>\n<p>&#064;RestControllerAdvice\u52a0\u5728\u5168\u5c40\u5f02\u5e38\u5904\u7406\u5668\u7684\u8fd9\u4e2a\u7c7b\u4e0a&#xff0c;\u800c&#064;ExceptionHandler\u52a0\u5728\u5f02\u5e38\u5904\u7406\u7684\u65b9\u6cd5\u4e0a&#xff0c;\u6765\u6307\u5b9a\u8fd9\u4e2a\u65b9\u6cd5\u6355\u83b7\u4ec0\u4e48\u6837\u7684\u5f02\u5e38\u3002 \u90a3\u5728\u5b9a\u4e49\u5f02\u5e38\u5904\u7406\u65b9\u6cd5\u7684\u65f6\u5019&#xff0c;\u53ef\u4ee5\u4e5f\u5b9a\u4e49\u591a\u4e2a&#xff0c;\u6839\u636e\u4e1a\u52a1\u7684\u9700\u6c42&#xff0c;\u53ef\u4ee5\u9488\u5bf9\u4e0d\u540c\u7c7b\u578b\u7684\u5f02\u5e38&#xff0c;\u8fdb\u884c\u4e0d\u540c\u7684\u5904\u7406\u3002<\/p>\n<hr \/>\n<h2>SpringBoot<\/h2>\n<h3>SpringBoot-bean\u7ba1\u7406<\/h3>\n<p>Bean\u626b\u63cf<\/p>\n<ul>\n<li>\n<p>\u6807\u7b7e<\/p>\n<p> <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token namespace\">context:<\/span>component-scan<\/span> <span class=\"token attr-name\">base-package<\/span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">&#061;<\/span><span class=\"token punctuation\">&#034;<\/span>com.lxx<span class=\"token punctuation\">&#034;<\/span><\/span><span class=\"token punctuation\">\/&gt;<\/span><\/span>\n <\/li>\n<li>\n<p>\u6ce8\u89e3<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;ComponentScan<\/span><span class=\"token punctuation\">(<\/span>basePackages <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;com.lxx&#034;<\/span><span class=\"token punctuation\">)<\/span>\n <\/li>\n<\/ul>\n<p>\u200b SpringBoot\u9ed8\u8ba4\u626b\u63cf\u542f\u52a8\u7c7b\u6240\u5728\u7684\u5305\u53ca\u5176\u5b50\u5305<\/p>\n<p>Bean\u6ce8\u518c<\/p>\n<p>&#064;Component\u3001&#064;Controller\u3001&#064;Service\u3001&#064;Repository<\/p>\n<p>\u5982\u679c\u8981\u6ce8\u518c\u7684bean\u5bf9\u8c61\u6765\u81ea\u4e8e\u7b2c\u4e09\u65b9&#xff08;\u4e0d\u662f\u81ea\u5b9a\u4e49\u7684&#xff09;&#xff0c;\u662f\u65e0\u6cd5\u7528 &#064;Component \u53ca\u884d\u751f\u6ce8\u89e3\u58f0\u660ebean\u7684<\/p>\n<ul>\n<li>\n<p>&#064;Bean<\/p>\n<p>\u5982\u679c\u8981\u6ce8\u518c\u7b2c\u4e09\u65b9bean&#xff0c;\u5efa\u8bae\u5728\u914d\u7f6e\u7c7b\u4e2d\u96c6\u4e2d\u6ce8\u518c<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Config<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">DataSource<\/span> <span class=\"token function\">getDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/\u5982\u679c\u65b9\u6cd5\u7684\u5185\u90e8\u9700\u8981\u4f7f\u7528\u5230ioc\u5bb9\u5668\u4e2d\u5df2\u7ecf\u5b58\u5728\u7684bean\u5bf9\u8c61,\u90a3\u4e48\u53ea\u9700\u8981\u5728\u65b9\u6cd5\u4e0a\u7684\u53c2\u6570\u4f4d\u7f6e\u58f0\u660e\u5373\u53ef,spring\u4f1a\u81ea\u52a8\u7684\u6ce8\u5165<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DruidDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<\/li>\n<li>\n<p>&#064;Import<\/p>\n<ul>\n<li>\n<p>\u5bfc\u5165 \u914d\u7f6e\u7c7b<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Import<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Config<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>\n <\/li>\n<li>\n<p>\u5bfc\u5165 ImportSelector \u63a5\u53e3\u5b9e\u73b0\u7c7b<\/p>\n<p> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">LxxImportSelector<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">ImportSelector<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token function\">selectImports<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">AnnotationMetadata<\/span> importingClassMetadata<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n       <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;com.alibaba.druid.pool.DruidDataSource&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n <span class=\"token annotation punctuation\">&#064;Import<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">LxxImportSelector<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>ImportSelector\u63a5\u53e3\u5b9e\u73b0\u7c7b\u4e2dselectImports\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4e0d\u5e94\u8be5\u4ee5\u786c\u7f16\u7801\u7684\u65b9\u5f0f\u5199\u6b7b&#xff0c;\u8fd9\u4e9b\u7c7b\u540d\u4e00\u822c\u662f\u4ece\u914d\u7f6e\u6587\u4ef6\u4e2d\u8bfb\u53d6\u7684\u3002<\/p>\n<p>\u5728resources\u4e0b\u65b0\u5efalxx.imports<\/p>\n<p> com.alibaba.druid.pool.DruidDataSource<\/p>\n<p>\u4fee\u6539LxxImportSelector<\/p>\n<p> <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">LxxImportSelector<\/span> <span class=\"token keyword\">implements<\/span> <span class=\"token class-name\">ImportSelector<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Override<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> <span class=\"token function\">selectImports<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">AnnotationMetadata<\/span> importingClassMetadata<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token comment\">\/\/\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6\u7684\u5185\u5bb9<\/span><br \/>\n        <span class=\"token class-name\">List<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">&gt;<\/span><\/span> imports <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">ArrayList<\/span><span class=\"token generics\"><span class=\"token punctuation\">&lt;<\/span><span class=\"token punctuation\">&gt;<\/span><\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">InputStream<\/span> is <span class=\"token operator\">&#061;<\/span> <span class=\"token class-name\">LxxImportSelector<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getClassLoader<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">getResourceAsStream<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;lxx.imports&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">BufferedReader<\/span> br <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">BufferedReader<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">InputStreamReader<\/span><span class=\"token punctuation\">(<\/span>is<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token class-name\">String<\/span> line <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">null<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">while<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">(<\/span>line <span class=\"token operator\">&#061;<\/span> br<span class=\"token punctuation\">.<\/span><span class=\"token function\">readLine<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><span class=\"token operator\">!&#061;<\/span><span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n                imports<span class=\"token punctuation\">.<\/span><span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span>line<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">IOException<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">RuntimeException<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">finally<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token keyword\">if<\/span> <span class=\"token punctuation\">(<\/span>br<span class=\"token operator\">!&#061;<\/span><span class=\"token keyword\">null<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n                <span class=\"token keyword\">try<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                    br<span class=\"token punctuation\">.<\/span><span class=\"token function\">close<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span> <span class=\"token keyword\">catch<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token class-name\">IOException<\/span> e<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n                    <span class=\"token keyword\">throw<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">RuntimeException<\/span><span class=\"token punctuation\">(<\/span>e<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n                <span class=\"token punctuation\">}<\/span><br \/>\n            <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> imports<span class=\"token punctuation\">.<\/span><span class=\"token function\">toArray<\/span><span class=\"token punctuation\">(<\/span><span class=\"token keyword\">new<\/span> <span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u5b9a\u4e49\u7ec4\u5408\u6ce8\u89e3&#xff0c;\u4f18\u5316&#064;Import(LxxImportSelector.class)<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Target<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">ElementType<\/span><span class=\"token punctuation\">.<\/span>TYPE<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;Retention<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">RetentionPolicy<\/span><span class=\"token punctuation\">.<\/span>RUNTIME<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;Import<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">LxxImportSelector<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token annotation punctuation\">&#064;interface<\/span> <span class=\"token class-name\">EnableLxxConfig<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n <span class=\"token annotation punctuation\">&#064;EnableLxxConfig<\/span><br \/>\n<span class=\"token annotation punctuation\">&#064;SpringBootApplication<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token keyword\">static<\/span> <span class=\"token keyword\">void<\/span> <span class=\"token function\">main<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">String<\/span><span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span> args<span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token class-name\">SpringApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token function\">run<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">HeimaSpringbootBasicsApplication<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">,<\/span> args<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>\n <\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u6ce8\u518c\u6761\u4ef6<\/p>\n<p>SpringBoot\u63d0\u4f9b\u4e86\u8bbe\u7f6e\u6ce8\u518c\u751f\u6548\u6761\u4ef6\u7684\u6ce8\u89e3 &#064;Conditional<\/p>\n<ul>\n<li>\n<p>&#064;ConditionalOnProperty&#xff1a;\u914d\u7f6e\u6587\u4ef6\u4e2d\u5b58\u5728\u5bf9\u5e94\u7684\u5c5e\u6027&#xff0c;\u624d\u58f0\u660e\u8be5bean<\/p>\n<p>\u5728application.yml\u4e2d\u914d\u7f6e<\/p>\n<p> <span class=\"token key atrule\">name<\/span><span class=\"token punctuation\">:<\/span> lxx<\/p>\n<p>\u6dfb\u52a0&#064;Conditional<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Config<\/span> <span class=\"token punctuation\">{<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token comment\">\/\/\u5982\u679c\u914d\u7f6e\u6587\u4ef6\u4e2d\u914d\u7f6e\u4e86\u6307\u5b9a\u7684\u4fe1\u606f,\u5219\u6ce8\u5165,\u5426\u5219\u4e0d\u6ce8\u5165<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;ConditionalOnProperty<\/span><span class=\"token punctuation\">(<\/span>name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;name&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">DataSource<\/span> <span class=\"token function\">getDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DruidDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<p> \u53bb\u9664application.yml\u4e2d\u7684name: lxx\u65f6&#xff1a;<br \/>\nHikariDataSource (null)<\/p>\n<p>\u52a0\u4e0aname: lxx\u65f6&#xff1a;<br \/>\n{<br \/>\nCreateTime:&#034;2023-12-21 14:00:17&#034;,<br \/>\nActiveCount:0,<br \/>\nPoolingCount:0,<br \/>\nCreateCount:0,<br \/>\nDestroyCount:0,<br \/>\nCloseCount:0,<br \/>\nConnectCount:0,<br \/>\nConnections:[<br \/>\n]<br \/>\n}\n <\/li>\n<li>\n<p>&#064;ConditionalOnBean&#xff1a;\u5f53\u5b58\u5728\u5f53\u524d\u7c7b\u578b\u7684bean\u65f6&#xff0c;\u624d\u58f0\u660e\u8be5bean<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Config<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Student<\/span> <span class=\"token function\">getStudent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Student<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5982\u679cioc\u5bb9\u5668\u4e2d\u5b58\u5728Student\u5219\u6ce8\u5165<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;ConditionalOnBean<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Student<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">DataSource<\/span> <span class=\"token function\">getDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DruidDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ \u7ed3\u679c&#xff1a;\u6ce8\u5165DataSource<\/span>\n <\/li>\n<li>\n<p>&#064;ConditionalOnMissingBean&#xff1a;\u5f53\u4e0d\u5b58\u5728\u5f53\u524d\u7c7b\u578b\u7684bean\u65f6&#xff0c;\u624d\u58f0\u660e\u8be5bean<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Config<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">Student<\/span> <span class=\"token function\">getStudent<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">Student<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token comment\">\/\/ \u5982\u679cioc\u5bb9\u5668\u4e2d\u4e0d\u5b58\u5728Student\u5219\u6ce8\u5165<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;ConditionalOnMissingBean<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Student<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">DataSource<\/span> <span class=\"token function\">getDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DruidDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token comment\">\/\/ \u7ed3\u679c&#xff1a;\u6ca1\u6709\u6ce8\u5165DataSource<\/span>\n <\/li>\n<li>\n<p>&#064;ConditionalOnClass&#xff1a;\u5f53\u524d\u73af\u5883\u5b58\u5728\u6307\u5b9a\u7684\u8fd9\u4e2a\u7c7b\u65f6&#xff0c;\u624d\u58f0\u660e\u8be5bean<\/p>\n<p> <span class=\"token annotation punctuation\">&#064;Configuration<\/span><br \/>\n<span class=\"token keyword\">public<\/span> <span class=\"token keyword\">class<\/span> <span class=\"token class-name\">Config<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;Bean<\/span><br \/>\n    <span class=\"token comment\">\/\/\u5982\u679c\u5f53\u524d\u73af\u5883\u4e2d\u5b58\u5728Student\u7c7b,\u5219\u6ce8\u5165,\u5426\u5219\u4e0d\u6ce8\u5165<\/span><br \/>\n    <span class=\"token annotation punctuation\">&#064;ConditionalOnClass<\/span><span class=\"token punctuation\">(<\/span><span class=\"token class-name\">Student<\/span><span class=\"token punctuation\">.<\/span><span class=\"token keyword\">class<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">public<\/span> <span class=\"token class-name\">DataSource<\/span> <span class=\"token function\">getDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token keyword\">new<\/span> <span class=\"token class-name\">DruidDataSource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span>\n <\/li>\n<\/ul>\n<hr \/>\n<h3>\u524d\u7f6e\u77e5\u8bc6<\/h3>\n<p>ApplicationContextInitializer&#xff1a;IOC\u5bb9\u5668\u521b\u5efa\u5b8c\u4e4b\u540e\u6267\u884c&#xff0c;\u53ef\u4ee5\u5bf9\u4e0a\u4e0b\u6587\u73af\u5883\u505a\u4e00\u4e9b\u64cd\u4f5c&#xff0c;\u4f8b\u5982\u8fd0\u884c\u73af\u5883\u5c5e\u6027\u6ce8\u518c\u7b49<\/p>\n<p>ApplicationListener&#xff1a;\u76d1\u542c\u5bb9\u5668\u53d1\u5e03\u7684\u4e8b\u4ef6&#xff0c;\u8fd0\u884c\u7a0b\u5e8f\u5458\u6267\u884c\u81ea\u5df1\u7684\u4ee3\u7801&#xff0c;\u5b8c\u6210\u4e8b\u4ef6\u9a71\u52a8\u5f00\u53d1&#xff0c;\u5b83\u53ef\u4ee5\u76d1\u542c\u5bb9\u5668\u521d\u59cb\u5316\u5b8c\u6210&#xff0c;\u521d\u59cb\u5316\u5931\u8d25\u7b49\u4e8b\u4ef6&#xff0c;\u901a\u5e38\u60c5\u51b5\u4e0b\u53ef\u4ee5\u4f7f\u7528\u76d1\u542c\u5668\u52a0\u8f7d\u8d44\u6e90&#xff0c;\u5f00\u542f\u5b9a\u65f6\u4efb\u52a1\u7b49<\/p>\n<p>BeanFactory&#xff1a;Bean\u5bb9\u5668\u7684\u6839\u63a5\u53e3&#xff0c;\u63d0\u4f9bBean\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u914d\u7f6e\u3001\u4f9d\u8d56\u6ce8\u5165\u7b49\u529f\u80fd<\/p>\n<p>BeanDefinition&#xff1a;\u7528\u4e8e\u63cf\u8ff0Bean&#xff0c;\u5305\u62ecBean\u7684\u540d\u79f0&#xff0c;Bean\u7684\u5c5e\u6027&#xff0c;Bean\u7684\u884c\u4e3a&#xff0c;\u5b9e\u73b0\u7684\u63a5\u53e3&#xff0c;\u6dfb\u52a0\u7684\u6ce8\u89e3\u7b49\u7b49\u3002Spring\u4e2d&#xff0c;Bean\u5728\u521b\u5efa\u4e4b\u524d&#xff0c;\u90fd\u9700\u8981\u5c01\u88c5\u6210\u5bf9\u5e94\u7684BeanDefinition&#xff0c;\u7136\u540e\u6839\u636eBeanDefinition\u8fdb\u4e00\u6b65\u521b\u5efaBean\u5bf9\u8c61<\/p>\n<p>BeanFactoryPostProcessor&#xff1a;Bean\u5de5\u5382\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5f53BeanFactory\u51c6\u5907\u597d\u4e4b\u540e&#xff08;Bean\u521d\u59cb\u5316\u4e4b\u524d&#xff09;\u4f1a\u8c03\u7528\u8be5\u63a5\u53e3\u7684postProcessBeanFactory\u65b9\u6cd5&#xff0c;\u7ecf\u5e38\u7528\u4e8e\u65b0\u589eBeanDefinition<\/p>\n<p>Aware&#xff1a;\u611f\u77e5\u63a5\u53e3&#xff0c;Spring\u63d0\u4f9b\u7684\u4e00\u79cd\u673a\u5236&#xff0c;\u901a\u8fc7\u5b9e\u73b0\u8be5\u63a5\u53e3&#xff0c;\u91cd\u5199\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u611f\u77e5Spring\u5e94\u7528\u7a0b\u5e8f\u6267\u884c\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e9b\u53d8\u5316\u3002Spring\u4f1a\u5224\u65ad\u5f53\u524d\u7684Bean\u6709\u6ca1\u6709\u5b9e\u73b0Aware\u63a5\u53e3&#xff0c;\u5982\u679c\u5b9e\u73b0\u4e86&#xff0c;\u4f1a\u5728\u7279\u5b9a\u7684\u65f6\u673a\u56de\u8c03\u63a5\u53e3\u4e2d\u5bf9\u5e94\u7684\u65b9\u6cd5<\/p>\n<p>InitializingBean\/DisposableBean&#xff1a;\u521d\u59cb\u5316\u63a5\u53e3&#xff0c;\u5f53Bean\u88ab\u5b9e\u4f8b\u5316\u597d\u540e&#xff0c;\u4f1a\u56de\u8c03\u91cc\u9762\u7684\u51fd\u6570&#xff0c;\u7ecf\u5e38\u7528\u4e8e\u505a\u4e00\u4e9b\u52a0\u8f7d\u8d44\u6e90\u7684\u5de5\u4f5c&#xff1b;\u9500\u6bc1\u63a5\u53e3&#xff0c;\u5f53Bean\u88ab\u9500\u6bc1\u4e4b\u524d&#xff0c;\u4f1a\u56de\u8c03\u91cc\u9762\u7684\u51fd\u6570&#xff0c;\u7ecf\u5e38\u7528\u4e8e\u505a\u4e00\u4e9b\u91ca\u653e\u8d44\u6e90\u7684\u5de5\u4f5c<\/p>\n<p>BeanPostProcessor&#xff1a;Bean\u7684\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5f53Bean\u5bf9\u8c61\u521d\u59cb\u5316\u4e4b\u524d\u4ee5\u53ca\u521d\u59cb\u5316\u4e4b\u540e&#xff0c;\u4f1a\u56de\u8c03\u8be5\u63a5\u53e3\u5bf9\u5e94\u7684\u65b9\u6cd5&#xff08;postProcessBeforeInitialization\u3001postProcessAfterInitialization&#xff09;<\/p>\n<h3>SpringBoot\u81ea\u52a8\u914d\u7f6e\u539f\u7406<\/h3>\n<ul>\n<li>\u5728\u4e3b\u542f\u52a8\u7c7b\u4e0a\u6dfb\u52a0\u4e86SpringBootApplication\u6ce8\u89e3,\u8fd9\u4e2a\u6ce8\u89e3\u7ec4\u5408\u4e86EnableAutoConfiguration\u6ce8\u89e3<\/li>\n<li>EnableAutoConfiguration\u6ce8\u89e3\u53c8\u7ec4\u5408\u4e86Import\u6ce8\u89e3,\u5bfc\u5165\u4e86AutoConfigurationImportSelector\u7c7b<\/li>\n<li>\u5b9e\u73b0selectImports\u65b9\u6cd5,\u8fd9\u4e2a\u65b9\u6cd5\u7ecf\u8fc7\u5c42\u5c42\u8c03\u7528,\u6700\u7ec8\u4f1a\u8bfb\u53d6META-INF \u76ee\u5f55\u4e0b\u7684 \u540e\u7f00\u540d \u4e3aimports\u7684\u6587\u4ef6,\u5f53\u7136\u4e86,boot2.7\u4ee5\u524d\u7684\u7248\u672c,\u8bfb\u53d6\u7684\u662fspring.factories\u6587\u4ef6<\/li>\n<li>\u8bfb\u53d6\u5230\u5168\u7c7b\u540d\u4e86\u4e4b\u540e,\u4f1a\u89e3\u6790\u6ce8\u518c\u6761\u4ef6,\u4e5f\u5c31\u662f&#064;Conditional\u53ca\u5176\u884d\u751f\u6ce8\u89e3,\u628a\u6ee1\u8db3\u6ce8\u518c\u6761\u4ef6\u7684Bean\u5bf9\u8c61\u81ea\u52a8\u6ce8\u5165\u5230IOC\u5bb9\u5668\u4e2d<\/li>\n<\/ul>\n<hr \/>\n<h3>SpringBoot\u7684\u542f\u52a8\u6d41\u7a0b<\/h3>\n<p>\u603b&#xff1a;SpringBoot\u542f\u52a8&#xff0c;\u5176\u672c\u8d28\u5c31\u662f\u52a0\u8f7d\u5404\u79cd\u914d\u7f6e\u4fe1\u606f&#xff0c;\u7136\u540e\u521d\u59cb\u5316IOC\u5bb9\u5668\u5e76\u8fd4\u56de<\/p>\n<p>\u5206&#xff1a;\u5728\u542f\u52a8\u7684\u8fc7\u7a0b\u4e2d\u4f1a\u505a\u8fd9\u4e48\u51e0\u4e2a\u4e8b\u60c5<\/p>\n<ul>\n<li>\u9996\u5148&#xff0c;\u5f53\u6211\u4eec\u5728\u542f\u52a8\u7c7b\u6267\u884cSpringApplication.run\u8fd9\u884c\u4ee3\u7801\u7684\u65f6\u5019&#xff0c;\u5728\u5b83\u7684\u65b9\u6cd5\u5185\u90e8\u5176\u5b9e\u4f1a\u505a\u4e24\u4e2a\u4e8b\u60c5\n<li>\u521b\u5efaSpringApplication\u5bf9\u8c61&#xff1b;<\/li>\n<li>\u6267\u884crun\u65b9\u6cd5\u3002<\/li>\n<\/li>\n<li>\u5176\u6b21&#xff0c;\u5728\u521b\u5efaSpringApplication\u5bf9\u8c61\u7684\u65f6\u5019&#xff0c;\u5728\u5b83\u7684\u6784\u9020\u65b9\u6cd5\u5185\u90e8\u4e3b\u8981\u505a3\u4e2a\u4e8b\u60c5\u3002\n<li>\u786e\u8ba4web\u5e94\u7528\u7c7b\u578b&#xff0c;\u4e00\u822c\u60c5\u51b5\u4e0b\u662fServlet\u7c7b\u578b&#xff0c;\u8fd9\u79cd\u7c7b\u578b\u7684\u5e94\u7528&#xff0c;\u5c06\u6765\u4f1a\u81ea\u52a8\u542f\u52a8\u4e00\u4e2atomcat<\/li>\n<li>\u4ecespring.factories\u914d\u7f6e\u6587\u4ef6\u4e2d&#xff0c;\u52a0\u8f7d\u9ed8\u8ba4\u7684ApplicationContextInitializer\u548cApplicationListener<\/li>\n<li>\u8bb0\u5f55\u5f53\u524d\u5e94\u7528\u7684\u4e3b\u542f\u52a8\u7c7b&#xff0c;\u5c06\u6765\u505a\u5305\u626b\u63cf\u4f7f\u7528<\/li>\n<\/li>\n<li>\u6700\u540e&#xff0c;\u5bf9\u8c61\u521b\u5efa\u597d\u4e86\u4ee5\u540e&#xff0c;\u518d\u8c03\u7528\u8be5\u5bf9\u8c61\u7684run\u65b9\u6cd5&#xff0c;\u5728run\u65b9\u6cd5\u7684\u5185\u90e8\u4e3b\u8981\u505a4\u4e2a\u4e8b\u60c5\n<li>\u51c6\u5907Environment\u5bf9\u8c61&#xff0c;\u5b83\u91cc\u9762\u4f1a\u5c01\u88c5\u4e00\u4e9b\u5f53\u524d\u5e94\u7528\u8fd0\u884c\u73af\u5883\u7684\u53c2\u6570&#xff0c;\u6bd4\u5982\u73af\u5883\u53d8\u91cf\u7b49\u7b49<\/li>\n<li>\u5b9e\u4f8b\u5316\u5bb9\u5668&#xff0c;\u8fd9\u91cc\u4ec5\u4ec5\u662f\u521b\u5efaApplicationContext\u5bf9\u8c61<\/li>\n<li>\u5bb9\u5668\u521b\u5efa\u597d\u4e4b\u540e&#xff0c;\u4f1a\u4e3a\u5bb9\u5668\u505a\u4e00\u4e9b\u51c6\u5907\u5de5\u4f5c&#xff0c;\u6bd4\u5982\u4e3a\u5bb9\u5668\u8bbe\u7f6eEnvironment&#xff0c;BeanFactoryPostProcessor-Bean\u5de5\u5382\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5e76\u52a0\u8f7d\u4e3b\u7c7b\u5bf9\u5e94\u7684BeanDefinition<\/li>\n<li>\u5237\u65b0\u5bb9\u5668&#xff0c;\u5c31\u662f\u6211\u4eec\u5e38\u8bf4\u7684referesh,\u5728\u8fd9\u91cc\u4f1a\u771f\u6b63\u7684\u521b\u5efaBean\u5b9e\u4f8b<\/li>\n<\/li>\n<\/ul>\n<p>\u603b&#xff1a;\u603b\u7ed3\u4e00\u4e0b\u6211\u521a\u8bf4\u7684&#xff0c;\u5176\u5b9eSpringBoot\u542f\u52a8\u7684\u6838\u5fc3\u5c31\u4e24\u6b65&#xff0c;\u521b\u5efaSpringApplication\u5bf9\u8c61\u4ee5\u53carun\u65b9\u6cd5\u7684\u8c03\u7528&#xff0c;\u5728run\u65b9\u6cd5\u4e2d\u4f1a\u771f\u6b63\u7684\u5b9e\u4f8b\u5316\u5bb9\u5668&#xff0c;\u5e76\u521b\u5efa\u5bb9\u5668\u4e2d\u9700\u8981\u7684Bean\u5b9e\u4f8b&#xff0c;\u6700\u7ec8\u8fd4\u56de\u3002<\/p>\n<hr \/>\n<h3>IOC\u5bb9\u5668\u7684\u521d\u59cb\u5316\u6d41\u7a0b<\/h3>\n<p>\u603b&#xff1a;IOC\u5bb9\u5668\u7684\u521d\u59cb\u5316&#xff0c;\u6838\u5fc3\u5de5\u4f5c\u662f\u5728AbstractApplicationContext.refresh()\u65b9\u6cd5\u4e2d\u5b8c\u6210\u7684<\/p>\n<p>\u5206&#xff1a;\u5728refresh()\u65b9\u6cd5\u4e2d\u4e3b\u8981\u505a\u4e86\u8fd9\u4e48\u51e0\u4ef6\u4e8b<\/p>\n<li>\u51c6\u5907BeanFactory-Bean\u5bb9\u5668\u7684\u6839\u63a5\u53e3&#xff08;\u63d0\u4f9bBean\u5bf9\u8c61\u7684\u521b\u5efa\u3001\u914d\u7f6e\u3001\u4f9d\u8d56\u6ce8\u5165\u7b49\u529f\u80fd&#xff09;&#xff0c;\u5728\u8fd9\u4e00\u5757\u9700\u8981\u7ed9BeanFactory\u8bbe\u7f6e\u5f88\u591a\u5c5e\u6027&#xff0c;\u6bd4\u5982\u7c7b\u52a0\u8f7d\u5668&#xff0c;Environment\u7b49<\/li>\n<li>\u6267\u884cBeanFactoryPostProcessor-Bean\u5de5\u5382\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u8fd9\u4e00\u9636\u6bb5\u4f1a\u626b\u63cf\u8981\u653e\u5165\u5230\u5bb9\u5668\u4e2d\u7684Bean\u4fe1\u606f&#xff0c;\u5f97\u5230\u5bf9\u5e94\u7684BeanDefinition&#xff08;\u6ce8\u610f&#xff1a;\u8fd9\u91cc\u53ea\u662f\u626b\u63cf&#xff0c;\u4e0d\u521b\u5efa&#xff09;<\/li>\n<li>\u6ce8\u518cBeanPostProcessor-Bean\u7684\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u6211\u4eec\u81ea\u5b9a\u4e49\u7684BeanPostProcessor\u5c31\u662f\u5728\u8fd9\u4e00\u9636\u6bb5\u88ab\u52a0\u8f7d\u7684&#xff0c;\u5c06\u6765Bean\u5bf9\u8c61\u5b9e\u4f8b\u5316\u597d\u540e\u9700\u8981\u7528\u5230<\/li>\n<li>\u542f\u52a8tomcat<\/li>\n<li>\u5b9e\u4f8b\u5316\u5bb9\u5668\u4e2d\u975e\u61d2\u52a0\u8f7d\u7684\u5355\u4f8bBean&#xff0c;\u8fd9\u91cc\u9700\u8981\u8bf4\u7684\u662f&#xff0c;\u591a\u4f8bBean\u548c\u61d2\u52a0\u8f7d\u7684Bean\u4e0d\u4f1a\u5728\u8fd9\u4e2a\u9636\u6bb5\u5b9e\u4f8b\u5316&#xff0c;\u5c06\u6765\u7528\u5230\u7684\u65f6\u5019\u518d\u521b\u5efa<\/li>\n<li>\u5bb9\u5668\u521d\u59cb\u5316\u5b8c\u6bd5\u540e&#xff0c;\u518d\u505a\u4e00\u4e9b\u626b\u5c3e\u5de5\u4f5c&#xff0c;\u6bd4\u5982\u6e05\u9664\u7f13\u5b58\u7b49<\/li>\n<p>\u603b&#xff1a;\u7b80\u5355\u603b\u7ed3\u4e00\u4e0b&#xff0c;\u5728IOC\u5bb9\u5668\u7684\u521d\u59cb\u5316\u8fc7\u7a0b\u4e2d&#xff0c;\u9996\u5148\u5f97\u51c6\u5907\u6267\u884cBeanFactoryPostProcessor-Bean\u5de5\u5382\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5176\u6b21\u5f97\u6ce8\u518cBeanPostProcessor-Bean\u7684\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5e76\u542f\u52a8tomcat&#xff0c;\u6700\u540e\u9700\u8981\u501f\u52a9\u4e8eBeanFactory\u5b8c\u6210Bean\u7684\u5b9e\u4f8b\u5316\u3002<\/p>\n<hr \/>\n<h3>Bean\u7684\u751f\u547d\u5468\u671f<\/h3>\n<p>\u603b&#xff1a;Bean\u7684\u751f\u547d\u5468\u671f\u603b\u7684\u6765\u8bf4\u67094\u4e2a\u9636\u6bb5&#xff0c;\u5206\u522b\u662f\u521b\u5efa\u5bf9\u8c61&#xff0c;\u521d\u59cb\u5316\u5bf9\u8c61&#xff0c;\u4f7f\u7528\u5bf9\u8c61\u4ee5\u53ca\u9500\u6bc1\u5bf9\u8c61&#xff0c;\u800c\u4e14\u8fd9\u4e9b\u5de5\u4f5c\u5927\u90e8\u5206\u90fd\u662f\u4ea4\u7ed9Bean\u5de5\u5382\u7684doCreateBean\u65b9\u6cd5\u5b8c\u6210\u7684<\/p>\n<p>\u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9996\u5148&#xff0c;\u5728\u521b\u5efa\u5bf9\u8c61\u9636\u6bb5&#xff0c;\u5148\u8c03\u7528\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316\u5bf9\u8c61&#xff0c;\u5bf9\u8c61\u6709\u4e86\u540e\u4f1a\u586b\u5145\u8be5\u5bf9\u8c61\u7684\u5185\u5bb9&#xff0c;\u5176\u5b9e\u5c31\u662f\u5904\u7406\u4f9d\u8d56\u6ce8\u5165<\/p>\n<\/li>\n<li>\n<p>\u5176\u6b21&#xff0c;\u5bf9\u8c61\u521b\u5efa\u5b8c\u6bd5\u540e&#xff0c;\u9700\u8981\u505a\u4e00\u4e9b\u521d\u59cb\u5316\u7684\u64cd\u4f5c&#xff0c;\u5728\u8fd9\u91cc\u6d89\u53ca\u5230\u51e0\u4e2a\u6269\u5c55\u70b9<\/p>\n<li>\u6267\u884cAware\u611f\u77e5\u63a5\u53e3\u7684\u56de\u8c03\u65b9\u6cd5<\/li>\n<li>\u6267\u884cBeanPostProcessor-Bean\u7684\u540e\u7f6e\u5904\u7406\u5668\u7684postProcessBeforeInitialization\u65b9\u6cd5<\/li>\n<li>\u6267\u884cInitializingBean\u63a5\u53e3\u7684\u56de\u8c03&#xff0c;\u5728\u8fd9\u4e00\u6b65\u5982\u679cBean\u4e2d\u6709\u6807\u6ce8\u4e86&#064;PostConstruct\u6ce8\u89e3\u7684\u65b9\u6cd5&#xff0c;\u4f1a\u5148\u6267\u884c\u5b83<\/li>\n<li>\u6267\u884cBeanPostProcessor-Bean\u7684\u540e\u7f6e\u5904\u7406\u5668\u7684postProcessAfterInitialization\u65b9\u6cd5<\/li>\n<p>\u628a\u8fd9\u4e9b\u6269\u5c55\u70b9\u90fd\u6267\u884c\u5b8c&#xff0c;Bean\u7684\u521d\u59cb\u5316\u5c31\u5b8c\u6210\u4e86<\/p>\n<\/li>\n<li>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u5728\u4f7f\u7528\u9636\u6bb5\u5c31\u662f\u7a0b\u5e8f\u5458\u4ece\u5bb9\u5668\u4e2d\u83b7\u53d6\u8be5Bean\u4f7f\u7528\u5373\u53ef<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e&#xff0c;\u5728\u5bb9\u5668\u9500\u6bc1\u4e4b\u524d&#xff0c;\u4f1a\u5148\u9500\u6bc1\u5bf9\u8c61&#xff0c;\u6b64\u65f6\u4f1a\u6267\u884cDisposableBean\u63a5\u53e3\u7684\u56de\u8c03&#xff0c;\u5728\u8fd9\u4e00\u6b65\u5982\u679cBean\u4e2d\u6709\u6807\u6ce8\u4e86&#064;PreDestroy\u6ce8\u89e3\u7684\u65b9\u6cd5&#xff0c;\u4f1a\u5148\u6267\u884c\u5b83<\/p>\n<\/li>\n<\/ul>\n<p>\u603b&#xff1a;\u7b80\u5355\u603b\u7ed3\u4e00\u4e0b&#xff0c;Bean\u7684\u751f\u547d\u5468\u671f\u5206\u4e3a4\u4e2a\u9636\u6bb5&#xff0c;\u5176\u4e2d\u521d\u59cb\u5316\u5bf9\u8c61\u548c\u9500\u6bc1\u5bf9\u8c61\u6211\u4eec\u7a0b\u5e8f\u5458\u53ef\u4ee5\u901a\u8fc7\u4e00\u4e9b\u6269\u5c55\u70b9\u6267\u884c\u81ea\u5df1\u7684\u4ee3\u7801<\/p>\n<p>\u5728 Spring Boot \u4e2d&#xff0c;\u63a8\u8350\u4f7f\u7528 &#064;PostConstruct \u548c &#064;PreDestroy \u6ce8\u89e3\u4ee3\u66ff XML \u914d\u7f6e\u7684 init-method \u548c destroy-method&#xff0c;\u8fd9\u662f Spring \u5b98\u65b9\u63a8\u8350\u7684 Java \u6807\u51c6\u65b9\u5f0f\u3002<\/p>\n<hr \/>\n<h3>Bean\u7684\u5faa\u73af\u4f9d\u8d56<\/h3>\n<p>\u603b&#xff1a;Bean\u7684\u5faa\u73af\u4f9d\u8d56\u6307\u7684\u662f\u00c0\u4f9d\u8d56B&#xff0c;B\u53c8\u4f9d\u8d56A\u8fd9\u6837\u7684\u4f9d\u8d56\u95ed\u73af\u95ee\u9898&#xff0c;\u5728Spring\u4e2d&#xff0c;\u901a\u8fc7\u4e09\u4e2a\u5bf9\u8c61\u7f13\u5b58\u533a\u6765\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u95ee\u9898&#xff0c;\u8fd9\u4e09\u4e2a\u7f13\u5b58\u533a\u88ab\u5b9a\u4e49\u5230\u4e86DefaultSingletonBeanRegistry\u4e2d&#xff0c;\u5206\u522b\u662fsingletonObjects&#xff08;\u6210\u54c1&#xff09;\u7528\u6765\u5b58\u50a8\u521b\u5efa\u5b8c\u6bd5\u7684Bean&#xff0c;earlySingletonObjecs&#xff08;\u534a\u6210\u54c1&#xff09;\u7528\u6765\u5b58\u50a8\u672a\u5b8c\u6210\u4f9d\u8d56\u6ce8\u5165\u7684Bean&#xff0c;\u8fd8\u6709SingletonFactories&#xff08;\u7528\u4e8e\u751f\u6210\u534a\u6210\u54c1 Bean&#xff09;\u7528\u6765\u5b58\u50a8\u521b\u5efaBean\u7684ObjectFactory\u3002\u5047\u5982\u8bf4\u73b0\u5728A\u4f9d\u8d56B&#xff0c;B\u4f9d\u8d56A&#xff0c;\u6574\u4e2a Bean\u7684\u521b\u5efa\u8fc7\u7a0b\u662f\u8fd9\u6837\u7684 \u5206&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u9996\u5148&#xff0c;\u8c03\u7528A\u7684\u6784\u9020\u65b9\u6cd5\u5b9e\u4f8b\u5316A&#xff0c;\u5f53\u524d\u7684A\u8fd8\u6ca1\u6709\u5904\u7406\u4f9d\u8d56\u6ce8\u5165&#xff0c;\u6682\u4e14\u628a\u5b83\u79f0\u4e3a\u534a\u6210\u54c1&#xff0c;\u6b64\u65f6\u4f1a\u628a\u534a\u6210\u54c1A\u5c01\u88c5\u5230\u4e00\u4e2a ObjectFactory\u4e2d&#xff0c;\u5e76\u5b58\u50a8\u5230singletonFactories\u7f13\u5b58\u533a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101726-697890b68f0f9.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u8981\u5904\u7406A\u7684\u4f9d\u8d56\u6ce8\u5165\u4e86&#xff0c;\u7531\u4e8e\u6b64\u65f6\u8fd8\u6ca1\u6709B&#xff0c;\u6240\u4ee5\u5f97\u5148\u5b9e\u4f8b\u5316\u4e00\u4e2aB&#xff0c;\u540c\u6837\u7684&#xff0c;\u534a\u6210\u54c1B\u4e5f\u4f1a\u88ab\u5c01\u88c5\u5230ObjectFactory\u4e2d\u5e76\u5b58\u50a8\u5230singletonFactories\u7f13\u5b58\u533a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101727-697890b702f2a.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>\u7d27\u63a5\u7740&#xff0c;\u8981\u5904\u7406B\u7684\u4f9d\u8d56\u6ce8\u5165\u4e86&#xff0c;\u6b64\u65f6\u4f1a\u627e\u5230singletonFactories\u4e2dA\u5bf9\u5e94\u7684ObjecFactory,\u8c03\u7528\u5b83\u7684getObject\u65b9\u6cd5\u5f97\u5230\u521a\u624d\u5b9e\u4f8b\u5316\u7684\u534a\u6210\u54c1A (\u5982\u679c\u9700\u8981\u4ee3\u7406\u5bf9\u8c61,\u5219\u4f1a\u81ea\u52a8\u521b\u5efa\u4ee3\u7406\u5bf9\u8c61,\u5c06\u6765\u5f97\u5230\u7684\u5c31\u662f\u4ee3\u7406\u5bf9\u8c61) &#xff0c;\u628a\u5f97\u5230\u7684\u534a\u6210\u54c1A\u6ce8\u5165\u7ed9B&#xff0c;\u5e76\u540c\u65f6\u4f1a\u628a\u534a\u6210\u54c1A\u5b58\u5165\u5230earlySingletonObjects\u4e2d&#xff0c;\u5c06\u6765\u5982\u679c\u8fd8\u6709\u5176\u4ed6\u7684\u7c7b\u5faa\u73af\u4f9d\u8d56\u4e86A&#xff0c;\u5c31\u53ef\u4ee5\u76f4\u63a5\u4eceearlySingletonObjects\u4e2d\u627e\u5230\u5b83\u4e86&#xff0c;\u90a3\u4e48\u6b64\u65f6 singletonFactories\u4e2d\u521b\u5efaA\u7684ObjectFactory\u4e5f\u53ef\u4ee5\u5220\u9664\u4e86<\/p>\n<\/li>\n<li>\n<p>\u81f3\u6b64&#xff0c;B\u7684\u4f9d\u8d56\u6ce8\u5165\u5904\u7406\u5b8c\u4e86\u540e&#xff0c;B\u5c31\u521b\u5efa\u5b8c\u6bd5\u4e86&#xff0c;\u5c31\u53ef\u4ee5\u628aB\u7684\u5bf9\u8c61\u5b58\u5165\u5230singletonObjects\u4e2d\u4e86&#xff0c;\u5e76\u540c\u65f6\u5220\u9664\u6389 singletonFactories\u4e2d\u521b\u5efaB\u7684ObjectFactory<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101727-697890b79a957.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<li>\n<p>B\u521b\u5efa\u5b8c\u6bd5\u540e&#xff0c;\u5c31\u53ef\u4ee5\u7ee7\u7eed\u5904\u7406A\u7684\u4f9d\u8d56\u6ce8\u5165\u4e86&#xff0c;\u628aB\u6ce8\u5165\u7ed9A&#xff0c;\u6b64\u65f6A\u4e5f\u521b\u5efa\u5b8c\u6bd5\u4e86&#xff0c;\u5c31\u53ef\u4ee5\u628aA\u7684\u5bf9\u8c61\u5b58\u50a8\u5230 singletonObjects\u4e2d&#xff0c;\u5e76\u540c\u65f6\u5220\u9664\u6389earlySingletonObjects\u4e2d\u7684\u534a\u6210\u54c1A<\/p>\n<\/li>\n<li>\n<p>\u622a\u6b64\u4e3a\u6b62&#xff0c;A\u548cB\u5bf9\u8c61\u5168\u90e8\u521b\u5efa\u5b8c\u6bd5&#xff0c;\u5e76\u5b58\u50a8\u5230\u4e86singletonObjects\u4e2d&#xff0c;\u5c06\u6765\u901a\u8fc7\u5bb9\u5668\u83b7\u53d6\u5bf9\u8c61&#xff0c;\u90fd\u662f\u4ecesingletonObejcts\u4e2d\u83b7\u53d6<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101728-697890b878f15.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<\/li>\n<\/ul>\n<p>\u603b&#xff1a;\u603b\u7ed3\u8d77\u6765\u8fd8\u662f\u4e00\u53e5\u8bdd&#xff0c;\u501f\u52a9\u4e8eDefaultSingletonBeanRegistry\u7684\u4e09\u4e2a\u7f13\u5b58\u533a\u53ef\u4ee5\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u95ee\u9898<\/p>\n<p>\u4e09\u7ea7\u7f13\u5b58\u7684\u5fc5\u8981\u6027&#xff1a;AOP \u4ee3\u7406\u7684\u5173\u952e\u4f5c\u7528<\/p>\n<p>\u5728\u7406\u89e3\u4e86\u4e09\u7ea7\u7f13\u5b58\u7684\u6838\u5fc3\u4f5c\u7528\u548c\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u7684\u6d41\u7a0b\u540e&#xff0c;\u6211\u4eec\u4e0d\u7981\u8981\u95ee&#xff1a;\u4e3a\u4ec0\u4e48 Spring \u9700\u8981\u4e09\u7ea7\u7f13\u5b58&#xff0c;\u800c\u4e0d\u662f\u4e24\u7ea7\u6216\u4e00\u7ea7\u7f13\u5b58\u5462&#xff1f;\u8fd9\u5176\u4e2d\u7684\u5173\u952e\u5728\u4e8e AOP \u4ee3\u7406\u7684\u5904\u7406\u3002<\/p>\n<p>\u5728 Spring \u4e2d&#xff0c;\u5f53\u4e00\u4e2a Bean \u9700\u8981\u88ab AOP \u589e\u5f3a\u65f6&#xff08;\u4f8b\u5982\u4f7f\u7528\u4e86&#064;Transactional\u6ce8\u89e3\u5f00\u542f\u4e8b\u52a1&#xff09;&#xff0c;Spring \u4f1a\u5728\u521d\u59cb\u5316\u9636\u6bb5\u751f\u6210\u4ee3\u7406\u5bf9\u8c61\u3002\u8fd9\u4e2a\u4ee3\u7406\u5bf9\u8c61\u5c31\u50cf\u662f\u7ed9\u539f\u59cb\u5bf9\u8c61\u7a7f\u4e0a\u4e86\u4e00\u5c42\u7279\u6b8a\u7684 \u201c\u5916\u8863\u201d&#xff0c;\u4f7f\u5176\u5177\u5907\u4e86\u989d\u5916\u7684\u529f\u80fd&#xff08;\u5982\u4e8b\u52a1\u7ba1\u7406\u3001\u65e5\u5fd7\u8bb0\u5f55\u7b49&#xff09;\u3002\u5982\u679c\u53ea\u6709\u4e24\u7ea7\u7f13\u5b58&#xff08;\u4e00\u7ea7\u7f13\u5b58\u5b58\u653e\u6210\u54c1 Bean&#xff0c;\u4e8c\u7ea7\u7f13\u5b58\u5b58\u653e\u534a\u6210\u54c1 Bean&#xff09;&#xff0c;\u5728\u586b\u5145\u5c5e\u6027\u65f6&#xff0c;\u6ce8\u5165\u7684\u5c06\u662f\u539f\u59cb\u5bf9\u8c61&#xff0c;\u800c\u4e0d\u662f\u4ee3\u7406\u5bf9\u8c61\u3002\u8fd9\u5c31\u597d\u6bd4\u7ed9\u4e00\u4e2a\u4eba\u7a7f\u4e0a\u4e86\u666e\u901a\u7684\u8863\u670d&#xff0c;\u800c\u4e0d\u662f\u4ed6\u9700\u8981\u7684\u7279\u6b8a \u201c\u5916\u8863\u201d&#xff0c;\u6700\u7ec8\u4f1a\u5bfc\u81f4\u6ce8\u5165\u7684\u5bf9\u8c61\u4e0e\u5b9e\u9645\u9700\u8981\u7684\u5bf9\u8c61\u4e0d\u4e00\u81f4&#xff0c;\u5f15\u53d1\u8fd0\u884c\u65f6\u5f02\u5e38\u3002<\/p>\n<p>\u800c\u4e09\u7ea7\u7f13\u5b58\u7684\u5b58\u5728&#xff0c;\u901a\u8fc7ObjectFactory\u5ef6\u8fdf\u4ee3\u7406\u751f\u6210&#xff0c;\u5de7\u5999\u5730\u89e3\u51b3\u4e86\u8fd9\u4e2a\u95ee\u9898\u3002\u5728\u5b58\u5728\u5faa\u73af\u4f9d\u8d56\u65f6&#xff0c;\u4e09\u7ea7\u7f13\u5b58\u4e2d\u7684\u5de5\u5382\u5bf9\u8c61\u4f1a\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u52a8\u6001\u751f\u6210\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u786e\u4fdd\u6ce8\u5165\u7684\u662f\u6700\u7ec8\u5f62\u6001\u7684 Bean\u3002\u4f8b\u5982&#xff0c;\u5f53 A \u88ab AOP \u589e\u5f3a\u65f6&#xff0c;\u5de5\u5382\u4f1a\u751f\u6210\u4ee3\u7406\u5bf9\u8c61\u5e76\u8fd4\u56de&#xff0c;\u800c\u4e0d\u662f\u539f\u59cb\u5bf9\u8c61\u3002\u8fd9\u6837\u5728\u6574\u4e2a\u5faa\u73af\u4f9d\u8d56\u7684\u89e3\u51b3\u8fc7\u7a0b\u4e2d&#xff0c;\u65e0\u8bba\u662f B \u5bf9 A \u7684\u4f9d\u8d56\u6ce8\u5165&#xff0c;\u8fd8\u662f\u6700\u7ec8 A \u7684\u521d\u59cb\u5316&#xff0c;\u4f7f\u7528\u7684\u90fd\u662f\u540c\u4e00\u4e2a\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u4fdd\u8bc1\u4e86\u5bf9\u8c61\u7684\u4e00\u81f4\u6027\u548c\u6b63\u786e\u6027\u3002<\/p>\n<p>Spring \u7684\u4e09\u7ea7\u7f13\u5b58\u673a\u5236\u901a\u8fc7\u5de7\u5999\u7684\u8bbe\u8ba1&#xff0c;\u4e0d\u4ec5\u6210\u529f\u89e3\u51b3\u4e86\u5faa\u73af\u4f9d\u8d56\u95ee\u9898&#xff0c;\u8fd8\u517c\u987e\u4e86 AOP \u4ee3\u7406\u7684\u5904\u7406&#xff0c;\u786e\u4fdd\u4e86 Spring \u5bb9\u5668\u4e2d Bean \u7684\u6b63\u786e\u521b\u5efa\u548c\u521d\u59cb\u5316&#xff0c;\u662f Spring \u6846\u67b6\u8bbe\u8ba1\u7684\u7cbe\u5999\u4e4b\u5904\u3002<\/p>\n<hr \/>\n<h3>\u804a\u804a\u4f60\u5bf9SpringBoot\u6846\u67b6\u7684\u7406\u89e3<\/h3>\n<p>SpringBoot\u662f\u73b0\u5728Spring\u5bb6\u65cf\u6700\u4e3a\u6d41\u884c\u7684\u5b50\u9879\u76ee&#xff0c;\u56e0\u4e3a\u91c7\u7528\u539f\u59cb\u7684SpringFramework\u6846\u67b6\u5f00\u53d1\u9879\u76ee&#xff0c;\u914d\u7f6e\u8d77\u6765\u975e\u5e38\u7684\u7e41\u7410&#xff0c;\u6240\u4ee5\u5728Spring\u76844.0 \u7248\u672c\u4e4b\u540e&#xff0c;Spring\u5bb6\u65cf\u63a8\u51fa\u4e86SpringBoot\u6846\u67b6&#xff0c;\u800cSpringboot\u5c31\u662f\u6765\u89e3\u51b3Spring\u6846\u67b6\u5f00\u53d1\u7e41\u7410\u7684\u95ee\u9898\u7684&#xff0c;\u662f\u7528\u6765\u7b80\u5316spring\u6846\u67b6\u5f00\u53d1\u7684\u3002<\/p>\n<p>\u4e3b\u8981\u63d0\u4f9b\u4e86\u8fd9\u4e48\u4e09\u5927\u5757\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>starter\u8d77\u6b65\u4f9d\u8d56\u3002springboot\u63d0\u4f9b\u4e86\u5404\u79cd\u5404\u6837\u7684starter&#xff0c;\u5728starter\u8d77\u6b65\u4f9d\u8d56\u4e2d&#xff0c;\u5c31\u5c01\u88c5\u4e86\u5e38\u7528\u7684\u4f9d\u8d56\u914d\u7f6e&#xff0c;\u5927\u5927\u7b80\u5316\u4e86\u9879\u76ee\u5f15\u5165\u4f9d\u8d56\u5750\u6807\u7684\u590d\u6742\u5ea6\u3002<\/li>\n<li>\u81ea\u52a8\u914d\u7f6e\u3002 \u8fd9\u4e5f\u662fspringboot\u4e2d\u6700\u6838\u5fc3\u7684\u529f\u80fd&#xff0c;springboot\u53ef\u4ee5\u6839\u636e\u7279\u5b9a\u7684\u6761\u4ef6&#xff08;\u5f53\u524d\u73af\u5883\u662f\u5426\u5f15\u5165\u5bf9\u5e94\u7684\u4f9d\u8d56\u3001\u914d\u7f6e\u6587\u4ef6\u4e2d\u662f\u5426\u6709\u67d0\u4e2a\u914d\u7f6e\u9879\u3001\u5f53\u524d\u73af\u5883\u662f\u5426\u5df2\u7ecf\u6709\u4e86\u67d0\u4e2abean&#xff09;\u6765\u521b\u5efa\u5bf9\u8c61\u7684bean&#xff0c;\u4ece\u800c\u5b8c\u6210bean\u7684\u81ea\u52a8\u914d\u7f6e\u3002<\/li>\n<li>jar\u5305\u65b9\u5f0f\u8fd0\u884c\u3002 springboot\u4e2d\u5185\u5d4c\u4e86web\u670d\u52a1\u5668&#xff0c;\u6240\u4ee5\u6211\u4eec\u5f00\u53d1\u7684web\u9879\u76ee&#xff0c;\u4e5f\u53ef\u4ee5\u76f4\u63a5\u6253\u6210\u4e00\u4e2ajar\u5305&#xff0c;\u76f4\u63a5\u57fa\u4e8ejava -jar \u6267\u884c\u8fd0\u884c&#xff0c;\u975e\u5e38\u7684\u65b9\u4fbf\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>SpringBoot\u5e94\u7528\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u5c11\u8bf7\u6c42&#xff1f;<\/h3>\n<p>SpringBoot\u9ed8\u8ba4\u7684\u5185\u5d4c\u5bb9\u5668\u662fTomcat&#xff0c;\u4e5f\u5c31\u662f\u6211\u4eec\u7684\u7a0b\u5e8f\u5b9e\u9645\u4e0a\u662f\u8fd0\u884c\u5728Tomcat\u91cc\u7684\u3002\u6240\u4ee5\u4e0e\u5176\u8bf4SpringBoot\u53ef\u4ee5\u5904\u7406\u591a\u5c11\u8bf7\u6c42&#xff0c;\u5230\u4e0d\u5982\u8bf4Tomcat\u53ef\u4ee5\u5904\u7406\u591a\u5c11\u8bf7\u6c42\u3002<\/p>\n<p>\u5728 application.properties \u6216 yml \u4e2d&#xff0c;\u4f60\u53ef\u4ee5\u770b\u5230\u8fd9\u4e9b\u914d\u7f6e&#xff1a;<\/p>\n<li>server.tomcat.threads.max (\u6700\u5927\u7ebf\u7a0b\u6570)\n<ul>\n<li>\u9ed8\u8ba4\u503c&#xff1a;200<\/li>\n<li>\u542b\u4e49&#xff1a; \u8fd9\u662f Tomcat \u771f\u6b63\u80fd\u540c\u65f6\u6267\u884c\u4e1a\u52a1\u903b\u8f91\u7684\u5de5\u4f5c\u7ebf\u7a0b\u6570\u3002<\/li>\n<li>\u7c7b\u6bd4&#xff1a; \u94f6\u884c\u67dc\u53f0\u91cc\u6b63\u5728\u529e\u7406\u4e1a\u52a1\u7684\u7a97\u53e3\u6570\u91cf\u3002\u5982\u679c 200 \u4e2a\u7a97\u53e3\u90fd\u5750\u6ee1\u4e86\u4eba&#xff0c;\u7b2c 201 \u4e2a\u4eba\u5c31\u9700\u8981\u7b49\u5f85\u3002<\/li>\n<\/ul>\n<\/li>\n<li>server.tomcat.max-connections (\u6700\u5927\u8fde\u63a5\u6570)\n<ul>\n<li>\u9ed8\u8ba4\u503c&#xff1a;8192 (\u5bf9\u4e8e NIO \u6a21\u5f0f)<\/li>\n<li>\u542b\u4e49&#xff1a; \u8fd9\u662f Tomcat \u80fd\u591f\u4fdd\u6301\u76d1\u542c\u7684\u6700\u5927 TCP \u8fde\u63a5\u6570\u3002<\/li>\n<li>\u7c7b\u6bd4&#xff1a; \u94f6\u884c\u5927\u5385\u91cc\u80fd\u5bb9\u7eb3\u7684\u603b\u4eba\u6570&#xff08;\u5305\u62ec\u6b63\u5728\u529e\u4e1a\u52a1\u7684\u548c\u5728\u6905\u5b50\u4e0a\u6392\u961f\u7b49\u5019\u7684&#xff09;\u3002<\/li>\n<li>\u6ce8\u610f&#xff1a; \u5373\u4f7f 200 \u4e2a\u7ebf\u7a0b\u90fd\u5728\u5fd9&#xff0c;\u5269\u4e0b\u7684 7992 \u4e2a\u8fde\u63a5\u4f9d\u7136\u53ef\u4ee5\u8fde\u4e0a\u6765&#xff0c;\u53ea\u662f\u5728\u6392\u961f&#xff0c;\u4e0d\u4f1a\u62a5\u9519\u3002<\/li>\n<\/ul>\n<\/li>\n<li>server.tomcat.accept-count (\u6700\u5927\u6392\u961f\u6570)\n<ul>\n<li>\u9ed8\u8ba4\u503c&#xff1a;100<\/li>\n<li>\u542b\u4e49&#xff1a; \u5f53\u8fde\u63a5\u6570\u8d85\u8fc7 8192 \u540e&#xff0c;\u64cd\u4f5c\u7cfb\u7edf&#xff08;OS&#xff09;\u8fd8\u53ef\u4ee5\u63a5\u53d7\u7684\u6392\u961f\u8bf7\u6c42\u3002<\/li>\n<li>\u7c7b\u6bd4&#xff1a; \u94f6\u884c\u5927\u5385\u4e5f\u7ad9\u4e0d\u4e0b\u4e86&#xff0c;\u5728\u94f6\u884c\u95e8\u53e3\u9732\u5929\u6392\u961f\u7684\u4eba\u6570\u3002\u5982\u679c\u8fd9\u4e2a\u6392\u961f\u4e5f\u6ee1\u4e86&#xff0c;\u65b0\u7684\u8bf7\u6c42\u4f1a\u88ab\u62d2\u7edd&#xff08;Connection Refused&#xff09;\u3002<\/li>\n<\/ul>\n<\/li>\n<p>\u7406\u8bba\u4e0a\u7684\u5e76\u53d1\u6781\u9650<\/p>\n<p>\u57fa\u4e8e\u9ed8\u8ba4\u914d\u7f6e&#xff1a;<\/p>\n<ul>\n<li>\u77ac\u65f6\u5e76\u53d1\u5904\u7406\u80fd\u529b&#xff1a; 200 \u4e2a\u8bf7\u6c42&#xff08;\u53d7 max-threads \u9650\u5236&#xff09;\u3002<\/li>\n<li>\u6700\u5927\u5bb9\u7eb3\u80fd\u529b&#xff1a; 8192 &#043; 100 &#061; 8292 \u4e2a\u8bf7\u6c42\u3002<\/li>\n<\/ul>\n<p>\u5982\u679c\u5e76\u53d1\u8bf7\u6c42\u6570\u91cf\u4f4e\u4e8eserver.tomcat.threads.max&#xff0c;\u5219\u4f1a\u88ab\u7acb\u5373\u5904\u7406&#xff0c;\u8d85\u8fc7\u7684\u90e8\u5206\u4f1a\u5148\u8fdb\u884c\u7b49\u5f85&#xff0c;\u5982\u679c\u6570\u91cf\u8d85\u8fc7max-connections\u4e0eaccept-count\u4e4b\u548c&#xff0c;\u5219\u591a\u4f59\u7684\u90e8\u5206\u5219\u4f1a\u88ab\u76f4\u63a5\u4e22\u5f03\u3002<\/p>\n<hr \/>\n<h2>SpringCloud<\/h2>\n<h3>\u5fae\u670d\u52a1\u8c03\u7528\u94fe\u573a\u666f&#xff1a;<\/h3>\n<li>\u7528\u6237\u8bf7\u6c42\u5148\u8fdbSpringCloudGateway&#xff0c;\u5728\u7f51\u5173\u5c42\u914d\u5408Sentinel\u505a\u9650\u6d41\u7194\u65ad&#xff0c;\u907f\u514d\u7a81\u53d1\u6d41\u91cf\u628a\u540e\u7aef\u6253\u7206&#xff1b;<\/li>\n<li>\u7f51\u5173\u8981\u627e\u670d\u52a1\u5730\u5740\u5c31\u53bbNacos\u67e5&#xff0c;\u62ff\u5230\u53ef\u7528\u5b9e\u4f8b\u5217\u8868&#xff1b;<\/li>\n<li>\u670d\u52a1\u4e4b\u95f4\u4e92\u76f8\u8c03\u7528&#xff0c;\u6bd4\u5982A\u8c03\u7528B\u7528OpenFegin&#xff0c;\u540c\u65f6\u901a\u8fc7LoadBalancer\u5728\u591a\u4e2a\u5b9e\u4f8b\u91cc\u505a\u8d1f\u8f7d\u5747\u8861&#xff1b;<\/li>\n<li>\u914d\u7f6e\u548b\u529e&#xff0c;\u7edf\u4e00\u653e\u5728NacosConfig\u4e00\u8d77\u7ef4\u62a4&#xff1b;<\/li>\n<li>\u8981\u662f\u4e0b\u6e38\u6302\u4e86&#xff0c;Sentinel\u8fd8\u80fd\u51fa\u624b\u8d70\u964d\u7ea7\u515c\u5e95&#xff0c;\u5148\u4fdd\u6838\u5fc3\u94fe\u8def&#xff1b;<\/li>\n<li>\u5f02\u6b65\u903b\u8f91\u4e22\u8fdbSpringCloudStream&#xff0c;\u9760 RabbitMQ\u6216RocketMQ\u6765\u89e3\u8026\u3001\u524a\u5cf0;<\/li>\n<li>\u8fd0\u7ef4\u548c\u6392\u67e5\u95ee\u9898&#xff0c;\u7528Sleuth &#043; Zipkin\u6216SkyWalking\u505a\u94fe\u8def\u8ffd\u8e2a&#xff0c;\u914d\u5408SpringBootAdmin\u770b\u76d1\u63a7;<\/li>\n<li>\u5206\u5e03\u5f0f\u4e8b\u52a1\u4f7f\u7528Seata&#xff0c;\u5206\u5e03\u5f0f\u9501\u4f7f\u7528Redisson<\/li>\n<hr \/>\n<h3>CAP\u5b9a\u7406<\/h3>\n<p>\u4e00\u81f4\u6027&#xff1a;Consistency&#xff08;\u4e00\u81f4\u6027&#xff09;&#xff0c;\u7528\u6237\u8bbf\u95ee\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u7684\u4efb\u610f\u8282\u70b9&#xff0c;\u5f97\u5230\u7684\u6570\u636e\u5fc5\u987b\u4e00\u81f4\u3002<\/p>\n<p>\u53ef\u7528\u6027&#xff1a;Availability &#xff08;\u53ef\u7528\u6027&#xff09;&#xff0c;\u7528\u6237\u8bbf\u95ee\u96c6\u7fa4\u4e2d\u7684\u4efb\u610f\u5065\u5eb7\u8282\u70b9&#xff0c;\u5fc5\u987b\u80fd\u5f97\u5230\u54cd\u5e94&#xff0c;\u800c\u4e0d\u662f\u8d85\u65f6\u6216\u62d2\u7edd\u3002<\/p>\n<p>\u5206\u533a\u5bb9\u9519&#xff1a;Partition&#xff08;\u5206\u533a&#xff09;&#xff1a;\u56e0\u4e3a\u7f51\u7edc\u6545\u969c\u6216\u5176\u5b83\u539f\u56e0\u5bfc\u81f4\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u7684\u90e8\u5206\u8282\u70b9\u4e0e\u5176\u5b83\u8282\u70b9\u5931\u53bb\u8fde\u63a5&#xff0c;\u5f62\u6210\u72ec\u7acb\u5206\u533a&#xff1b;Tolerance&#xff08;\u5bb9\u9519**&#xff09;**&#xff1a;\u5728\u96c6\u7fa4\u51fa\u73b0\u5206\u533a\u65f6&#xff0c;\u6574\u4e2a\u7cfb\u7edf\u4e5f\u8981\u6301\u7eed\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1<\/p>\n<p>\u77db\u76fe&#xff1a;<\/p>\n<p>\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d&#xff0c;\u7cfb\u7edf\u95f4\u7684\u7f51\u7edc\u4e0d\u80fd100%\u4fdd\u8bc1\u5065\u5eb7&#xff0c;\u4e00\u5b9a\u4f1a\u6709\u6545\u969c\u7684\u65f6\u5019&#xff0c;\u800c\u670d\u52a1\u6709\u5fc5\u987b\u5bf9\u5916\u4fdd\u8bc1\u670d\u52a1\u3002\u56e0\u6b64\u5206\u533a\u5bb9\u9519Partition Tolerance\u4e0d\u53ef\u907f\u514d\u3002<\/p>\n<p>\u5f53\u8282\u70b9\u63a5\u6536\u5230\u65b0\u7684\u6570\u636e\u53d8\u66f4\u65f6&#xff0c;\u5c31\u4f1a\u51fa\u73b0\u95ee\u9898\u4e86&#xff1a; <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101728-697890b8d7bdc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5982\u679c\u6b64\u65f6\u8981\u4fdd\u8bc1\u4e00\u81f4\u6027&#xff0c;\u5c31\u5fc5\u987b\u7b49\u5f85\u7f51\u7edc\u6062\u590d&#xff0c;\u5b8c\u6210\u6570\u636e\u540c\u6b65\u540e&#xff0c;\u6574\u4e2a\u96c6\u7fa4\u624d\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1&#xff0c;\u670d\u52a1\u5904\u4e8e\u963b\u585e\u72b6\u6001&#xff0c;\u4e0d\u53ef\u7528\u3002<\/p>\n<p>\u5982\u679c\u6b64\u65f6\u8981\u4fdd\u8bc1\u53ef\u7528\u6027&#xff0c;\u5c31\u4e0d\u80fd\u7b49\u5f85\u7f51\u7edc\u6062\u590d&#xff0c;\u90a3node01\u3001node02\u4e0enode03\u4e4b\u95f4\u5c31\u4f1a\u51fa\u73b0\u6570\u636e\u4e0d\u4e00\u81f4\u3002<\/p>\n<p>\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u5728P\u4e00\u5b9a\u4f1a\u51fa\u73b0\u7684\u60c5\u51b5\u4e0b&#xff0c;A\u548cC\u4e4b\u95f4\u53ea\u80fd\u5b9e\u73b0\u4e00\u4e2a\u3002<\/p>\n<hr \/>\n<h3>BASE\u7406\u8bba<\/h3>\n<p>BASE\u7406\u8bba\u662f\u5bf9CAP\u7684\u4e00\u79cd\u89e3\u51b3\u601d\u8def&#xff0c;\u5305\u542b\u4e09\u4e2a\u601d\u60f3&#xff1a;<\/p>\n<p>Basically Available &#xff08;\u57fa\u672c\u53ef\u7528&#xff09;&#xff1a;\u5206\u5e03\u5f0f\u7cfb\u7edf\u5728\u51fa\u73b0\u6545\u969c\u65f6&#xff0c;\u5141\u8bb8\u635f\u5931\u90e8\u5206\u53ef\u7528\u6027&#xff0c;\u5373\u4fdd\u8bc1\u6838\u5fc3\u53ef\u7528\u3002 Soft State&#xff08;\u8f6f\u72b6\u6001&#xff09;&#xff1a; :\u5728\u4e00\u5b9a\u65f6\u95f4\u5185&#xff0c;\u5141\u8bb8\u51fa\u73b0\u4e2d\u95f4\u72b6\u6001&#xff0c;\u6bd4\u5982\u4e34\u65f6\u7684\u4e0d\u4e00\u81f4\u72b6\u6001\u3002 Eventually Consistent&#xff08;\u6700\u7ec8\u4e00\u81f4\u6027&#xff09;&#xff1a;\u867d\u7136\u65e0\u6cd5\u4fdd\u8bc1\u5f3a\u4e00\u81f4\u6027&#xff0c;\u4f46\u662f\u5728\u8f6f\u72b6\u6001\u7ed3\u675f\u540e&#xff0c;\u6700\u7ec8\u8fbe\u5230\u6570\u636e\u4e00\u81f4\u3002<\/p>\n<hr \/>\n<h3>\u89e3\u51b3\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u601d\u8def<\/h3>\n<p>\u5206\u5e03\u5f0f\u4e8b\u52a1\u6700\u5927\u7684\u95ee\u9898\u662f\u5404\u4e2a\u5b50\u4e8b\u52a1\u7684\u4e00\u81f4\u6027\u95ee\u9898&#xff0c;\u56e0\u6b64\u53ef\u4ee5\u501f\u9274CAP\u5b9a\u7406\u548cBASE\u7406\u8bba&#xff0c;\u6709\u4e24\u79cd\u89e3\u51b3\u601d\u8def&#xff1a;<\/p>\n<ul>\n<li>\n<p>AP\u6a21\u5f0f&#xff1a;\u5404\u5b50\u4e8b\u52a1\u5206\u522b\u6267\u884c\u548c\u63d0\u4ea4&#xff0c;\u5141\u8bb8\u51fa\u73b0\u7ed3\u679c\u4e0d\u4e00\u81f4&#xff0c;\u7136\u540e\u91c7\u7528\u5f25\u8865\u63aa\u65bd\u6062\u590d\u6570\u636e\u5373\u53ef&#xff0c;\u5b9e\u73b0\u6700\u7ec8\u4e00\u81f4\u3002<\/p>\n<\/li>\n<li>\n<p>CP\u6a21\u5f0f&#xff1a;\u5404\u4e2a\u5b50\u4e8b\u52a1\u6267\u884c\u540e\u4e92\u76f8\u7b49\u5f85&#xff0c;\u540c\u65f6\u63d0\u4ea4&#xff0c;\u540c\u65f6\u56de\u6eda&#xff0c;\u8fbe\u6210\u5f3a\u4e00\u81f4\u3002\u4f46\u4e8b\u52a1\u7b49\u5f85\u8fc7\u7a0b\u4e2d&#xff0c;\u5904\u4e8e\u5f31\u53ef\u7528\u72b6\u6001\u3002<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h3>Seata\u6a21\u5f0f<\/h3>\n<p>Seata\u5206\u5e03\u5f0f\u4e8b\u52a1\u7684\u56db\u79cd\u6a21\u5f0f<\/p>\n<ul>\n<li>AT\u6a21\u5f0f&#xff0c;\u9ed8\u8ba4&#xff0c;\u7b80\u5355&#xff0c;\u9700\u8981\u589e\u52a0undo_log\u8868&#xff0c;\u751f\u6210\u53cd\u5411SQL&#xff0c;\u6027\u80fd\u9ad8<\/li>\n<li>TCC\u6a21\u5f0f&#xff0c;try confirm\/cancel&#xff0c;\u4e09\u4e2a\u9636\u6bb5\u7684\u4ee3\u7801\u90fd\u5f97\u81ea\u5df1\u5b9e\u73b0&#xff0c;Seata\u53ea\u8d1f\u8d23\u8c03\u5ea6<\/li>\n<li>SAGA\u6a21\u5f0f&#xff0c;\u957f\u4e8b\u52a1\u89e3\u51b3\u65b9\u6848<\/li>\n<li>XA\u6a21\u5f0f&#xff0c;\u5206\u5e03\u5f0f\u5f3a\u4e00\u81f4\u6027\u7684\u89e3\u51b3\u65b9\u6848&#xff0c;\u4f46\u6027\u80fd\u4f4e\u800c\u4f7f\u7528\u8f83\u5c11\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>\u8d1f\u8f7d\u5747\u8861\u7684\u610f\u4e49<\/h3>\n<p>\u8d1f\u8f7d\u5e73\u8861\u80fd\u4f18\u5316\u8d44\u6e90\u4f7f\u7528&#xff0c;\u6700\u5927\u5316\u541e\u5410\u91cf&#xff0c;\u5e76\u907f\u514d\u4efb\u4f55\u5355\u4e00\u8d44\u6e90\u7684\u8fc7\u8f7d.<\/p>\n<p>\u7b80\u5355\u6765\u8bf4, \u67d0\u4e2a\u670d\u52a1\u5668\u53ea\u80fd\u627f\u53d7100\u5e76\u53d1, \u53e6\u5916\u4e00\u4e2a\u80fd\u627f\u53d7200\u5e76\u53d1. \u90a3\u4e48\u8bf7\u6c42\u88ab\u8f6c\u53d1\u5230\u7b2c\u4e00\u53f0\u670d\u52a1\u5668\u548c\u7b2c\u4e8c\u53f0\u670d\u52a1\u5668\u7684\u6bd4\u4f8b\u5e94\u8be5\u662f1:2. \u7b2c\u4e8c\u53f0\u670d\u52a1\u5668\u5e94\u8be5\u63a5\u53d7\u66f4\u591a\u8bf7\u6c42, \u907f\u514d\u7b2c\u4e00\u53f0\u670d\u52a1\u63a5\u53d7\u66f4\u591a\u8bf7\u6c42\u4ea7\u751f\u8fc7\u8f7d.<\/p>\n<hr \/>\n<h3>\u8d1f\u8f7d\u5747\u8861\u5e38\u89c1\u5b9e\u73b0\u7b56\u7565<\/h3>\n<ul>\n<li>\u7b80\u5355\u8f6e\u8be2&#xff1a;\u5c06\u8bf7\u6c42\u6309\u987a\u5e8f\u5206\u53d1\u7ed9\u540e\u7aef\u670d\u52a1\u5668\u4e0a&#xff0c;\u4e0d\u5173\u5fc3\u670d\u52a1\u5668\u5f53 \u524d\u7684\u72b6\u6001&#xff0c;\u6bd4\u5982\u540e\u7aef\u670d\u52a1\u5668\u7684\u6027\u80fd\u3001\u5f53\u524d\u7684\u8d1f\u8f7d<\/li>\n<li>\u52a0\u6743\u8f6e\u8be2&#xff1a;\u6839\u636e\u670d\u52a1\u5668\u81ea\u8eab\u7684\u6027\u80fd\u7ed9\u670d\u52a1\u5668\u8bbe\u7f6e\u4e0d\u540c\u7684\u6743\u91cd&#xff0c;\u5c06 \u8bf7\u6c42\u6309\u987a\u5e8f\u548c\u6743\u91cd\u5206\u53d1\u7ed9\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u53ef\u4ee5\u8ba9\u6027\u80fd\u9ad8\u7684\u673a\u5668\u5904\u7406 \u66f4\u591a\u7684\u8bf7\u6c42<\/li>\n<li>\u7b80\u5355\u968f\u673a&#xff1a;\u5c06\u8bf7\u6c42\u968f\u673a\u5206\u53d1\u7ed9\u540e\u7aef\u670d\u52a1\u5668\u4e0a&#xff0c;\u8bf7\u6c42\u8d8a\u591a&#xff0c;\u5404\u4e2a\u670d \u52a1\u5668\u63a5\u6536\u5230\u7684\u8bf7\u6c42\u8d8a\u5e73\u5747<\/li>\n<li>\u52a0\u6743\u968f\u673a&#xff1a;\u6839\u636e\u670d\u52a1\u5668\u81ea\u8eab\u7684\u6027\u80fd\u7ed9\u670d\u52a1\u5668\u8bbe\u7f6e\u4e0d\u540c\u7684\u6743\u91cd&#xff0c;\u5c06 \u8bf7\u6c42\u6309\u5404\u4e2a\u670d\u52a1\u5668\u7684\u6743\u91cd\u968f\u673a\u5206\u53d1\u7ed9\u540e\u7aef\u670d\u52a1\u5668<\/li>\n<li>\u4e00\u81f4\u6027\u54c8\u5e0c&#xff1a;\u6839\u636e\u8bf7\u6c42\u7684\u5ba2\u6237\u7aefip\u3001\u6216\u8bf7\u6c42\u53c2\u6570\u901a\u8fc7\u54c8\u5e0c\u7b97\u6cd5\u5f97 \u5230\u4e00\u4e2a\u6570\u503c&#xff0c;\u5229\u7528\u8be5\u6570\u503c\u53d6\u6a21\u6620\u5c04\u51fa\u5bf9\u5e94\u7684\u540e\u7aef\u670d\u52a1\u5668&#xff0c;\u8fd9\u6837\u80fd \u4fdd\u8bc1\u540c\u4e00\u4e2a\u5ba2\u6237\u7aef\u6216\u76f8\u540c\u53c2\u6570\u7684\u8bf7\u6c42\u6bcf\u6b21\u90fd\u4f7f\u7528\u540c\u4e00\u53f0\u670d\u52a1\u5668<\/li>\n<li>\u6700\u5c0f\u6d3b\u8dc3\u6570&#xff1a;\u7edf\u8ba1\u6bcf\u53f0\u670d\u52a1\u5668\u4e0a\u5f53\u524d\u6b63\u5728\u5904\u7406\u7684\u8bf7\u6c42\u6570&#xff0c;\u4e5f\u5c31\u662f \u8bf7\u6c42\u6d3b\u8dc3\u6570&#xff0c;\u5c06\u8bf7\u6c42\u5206\u53d1\u7ed9\u6d3b\u8dc3\u6570\u6700\u5c11\u7684\u540e\u53f0\u670d\u52a1\u5668<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4ec0\u4e48\u662f\u670d\u52a1\u964d\u7ea7&#xff1f;\u4ec0\u4e48\u662f\u670d\u52a1\u7194\u65ad&#xff1f;\u4ec0\u4e48\u662f\u670d\u52a1\u9650\u6d41&#xff1f;\u8fd9\u4e09\u8005\u53c8\u662f\u4ec0\u4e48\u5173\u7cfb&#xff1f;<\/h3>\n<p>\u5148\u8bf4\u4eba\u8bdd\u7248\u672c&#xff1a;\u9650\u6d41\u662f\u95e8\u53e3\u4fdd\u5b89&#xff0c;\u7194\u65ad\u662f\u81ea\u52a8\u8df3\u95f8&#xff0c;\u964d\u7ea7\u662f\u5907\u7528\u65b9\u6848\u3002<\/p>\n<p>\u573a\u666f&#xff1a;<\/p>\n<p>\u53bb\u5e74\u53cc\u5341\u4e00&#xff0c;\u5546\u54c1\u670d\u52a1\u625b\u4e0d\u4f4f\u6302\u4e86\u3002<\/p>\n<p>\u7136\u540e\u8ba2\u5355\u670d\u52a1\u8c03\u5546\u54c1\u670d\u52a1&#xff0c;\u4e00\u76f4\u8d85\u65f6&#xff0c;\u7ebf\u7a0b\u5168\u5361\u5728\u90a3\u7b49\u7740\u3002\u7528\u6237\u670d\u52a1\u8c03\u8ba2\u5355\u670d\u52a1&#xff0c;\u4e5f\u8d85\u65f6&#xff0c;\u7ebf\u7a0b\u6c60\u4e5f\u6ee1\u4e86\u3002\u5341\u5206\u949f\u4e0d\u5230&#xff0c;\u6574\u6761\u94fe\u8def\u5168\u5d29\u4e86&#xff0c;\u9996\u9875\u90fd\u6253\u4e0d\u5f00\u3002<\/p>\n<p>\u7528\u6237\u8bf7\u6c42<br \/>\n    \u2502<br \/>\n    \u25bc<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510    \u8c03\u7528    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510    \u8c03\u7528    \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502 \u7528\u6237\u670d\u52a1 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 \u2502 \u8ba2\u5355\u670d\u52a1 \u2502 \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25b6 \u2502 \u5546\u54c1\u670d\u52a1 \u2502 \u2190 \u6302\u4e86<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518           \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518           \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n                           \u2502<br \/>\n                           \u25bc<br \/>\n                      \u7ebf\u7a0b\u50bb\u7b49\u8d85\u65f6<br \/>\n                           \u2502<br \/>\n                           \u25bc<br \/>\n                      \u7ebf\u7a0b\u6c60\u6ee1\u4e86<br \/>\n                           \u2502<br \/>\n                           \u25bc<br \/>\n                      \u5168\u5b8c\u86cb<\/p>\n<p>\u8fd9\u5c31\u662f\u96ea\u5d29\u3002\u4e00\u4e2a\u670d\u52a1\u6302&#xff0c;\u62d6\u6b7b\u4e00\u4e32\u3002<\/p>\n<p>\u5f53\u65f6\u8981\u662f\u914d\u597d\u4e86\u9650\u6d41\u7194\u65ad\u964d\u7ea7&#xff0c;\u81f3\u5c11\u4e0d\u4f1a\u5168\u5d29&#xff0c;\u9876\u591a\u5546\u54c1\u8be6\u60c5\u9875\u770b\u4e0d\u4e86&#xff0c;\u9996\u9875\u548c\u8ba2\u5355\u5217\u8868\u8fd8\u80fd\u7528\u3002<\/p>\n<p>\u9650\u6d41<\/p>\n<p>\u5c31\u662f\u63a7\u5236\u6d41\u91cf&#xff0c;\u522b\u8ba9\u592a\u591a\u8bf7\u6c42\u8fdb\u6765\u628a\u81ea\u5df1\u538b\u6b7b\u3002<\/p>\n<p>\u666f\u533a\u9650\u6d41\u4f60\u61c2\u5427&#xff1f;\u6bcf\u5929\u5c31\u653e5\u4e07\u4eba\u8fdb\u53bb&#xff0c;\u591a\u4e86\u5c31\u522b\u8fdb\u4e86\u3002\u7cfb\u7edf\u4e5f\u4e00\u6837&#xff0c;\u4f60\u80fd\u62971000 QPS&#xff0c;\u6765\u4e865000\u5c31\u5f97\u6321\u63894000\u3002<\/p>\n<p>\u5e38\u89c1\u7684\u9650\u6d41\u7b97\u6cd5&#xff0c;\u4ee4\u724c\u6876\u548c\u6f0f\u6876]\u7528\u5f97\u6700\u591a\u3002\u4ee4\u724c\u6876\u5c31\u662f\u7cfb\u7edf\u6309\u56fa\u5b9a\u901f\u7387\u5f80\u6876\u91cc\u653e\u4ee4\u724c&#xff0c;\u8bf7\u6c42\u6765\u4e86\u5148\u62ff\u4ee4\u724c&#xff0c;\u6ca1\u4ee4\u724c\u5c31\u62d2\u7edd\u3002\u597d\u5904\u662f\u80fd\u5e94\u5bf9\u7a81\u53d1\u6d41\u91cf&#xff0c;\u6876\u91cc\u6512\u4e86\u4e00\u5806\u4ee4\u724c\u7684\u8bdd&#xff0c;\u77ed\u65f6\u95f4\u80fd\u653e\u8fc7\u53bb\u66f4\u591a\u8bf7\u6c42\u3002\u6f0f\u6876\u5462&#xff0c;\u8bf7\u6c42\u5148\u8fdb\u6876&#xff0c;\u7136\u540e\u5300\u901f\u6d41\u51fa&#xff0c;\u4e0d\u7ba1\u4f60\u8fdb\u6765\u591a\u5feb&#xff0c;\u51fa\u53bb\u7684\u901f\u5ea6\u662f\u56fa\u5b9a\u7684\u3002<\/p>\n<p>\u8d85\u8fc7100\u5c31\u76f4\u63a5\u8fd4\u56de\u201d\u7cfb\u7edf\u7e41\u5fd9\u201d&#xff0c;\u4e0d\u8ba9\u8bf7\u6c42\u8fdb\u6765\u3002<\/p>\n<p>\u7194\u65ad<\/p>\n<p>\u4e0b\u6e38\u6302\u4e86\u5c31\u522b\u8c03\u4e86&#xff0c;\u5feb\u901f\u5931\u8d25&#xff0c;\u522b\u50bb\u7b49\u3002<\/p>\n<p>\u8fd9\u540d\u5b57\u6765\u81ea\u7535\u8def\u91cc\u7684\u4fdd\u9669\u4e1d&#xff0c;\u7535\u6d41\u592a\u5927\u5c31\u7194\u65ad&#xff0c;\u9632\u6b62\u628a\u6574\u4e2a\u7535\u8def\u70e7\u4e86\u3002<\/p>\n<p>\u7194\u65ad\u5668\u6709\u4e09\u4e2a\u72b6\u6001&#xff0c;\u6b63\u5e38\u7684\u65f6\u5019\u662f\u5173\u95ed\u72b6\u6001&#xff0c;\u8bf7\u6c42\u6b63\u5e38\u8fc7\u3002\u5931\u8d25\u591a\u4e86\u5c31\u6253\u5f00&#xff0c;\u6253\u5f00\u4e4b\u540e\u8bf7\u6c42\u76f4\u63a5\u5931\u8d25&#xff0c;\u6839\u672c\u4e0d\u8c03\u4e0b\u6e38\u4e86\u3002\u8fc7\u4e00\u4f1a\u8fdb\u5165\u534a\u5f00\u72b6\u6001&#xff0c;\u653e\u51e0\u4e2a\u8bf7\u6c42\u8bd5\u8bd5\u6c34&#xff0c;\u597d\u4e86\u5c31\u6062\u590d\u6b63\u5e38&#xff0c;\u6ca1\u597d\u7ee7\u7eed\u7194\u65ad\u3002<\/p>\n<p>\u4e3e\u4e2a\u4f8b\u5b50\u5427\u3002\u5546\u54c1\u670d\u52a1\u54cd\u5e94\u4ece100ms\u53d8\u6210\u4e865\u79d2&#xff0c;\u53ef\u80fd\u662f\u6570\u636e\u5e93\u6162\u67e5\u8be2\u5565\u7684\u3002<\/p>\n<p>\u6ca1\u7194\u65ad\u7684\u8bdd&#xff0c;\u6bcf\u4e2a\u8bf7\u6c42\u90fd\u8981\u7b495\u79d2\u624d\u8d85\u65f6\u5931\u8d25&#xff0c;\u7ebf\u7a0b\u90fd\u5361\u7740&#xff0c;\u5f88\u5feb\u7ebf\u7a0b\u6c60\u5c31\u6ee1\u4e86&#xff0c;\u540e\u9762\u7684\u8bf7\u6c42\u6392\u961f&#xff0c;\u6700\u540e\u6574\u4e2a\u670d\u52a1\u5361\u6b7b\u3002<\/p>\n<p>\u6709\u7194\u65ad\u5c31\u4e0d\u4e00\u6837\u4e86\u3002\u53d1\u73b0\u6700\u8fd110\u4e2a\u8bf7\u6c42\u67095\u4e2a\u8d85\u65f6\u4e86&#xff0c;\u76f4\u63a5\u89e6\u53d1\u7194\u65ad&#xff0c;\u540e\u7eed\u8bf7\u6c42\u538b\u6839\u4e0d\u8c03\u5546\u54c1\u670d\u52a1&#xff0c;\u76f4\u63a5\u8fd4\u56de\u5931\u8d25\u3002\u7b4910\u79d2\u540e&#xff0c;\u653e\u51e0\u4e2a\u8bf7\u6c42\u8bd5\u8bd5&#xff0c;\u597d\u4e86\u5c31\u6062\u590d&#xff0c;\u6ca1\u597d\u7ee7\u7eed\u7194\u65ad\u3002<\/p>\n<p>\u5173\u952e\u5c31\u662f\u5feb\u901f\u5931\u8d25&#xff0c;\u522b\u8ba9\u7ebf\u7a0b\u50bb\u7b49\u3002<\/p>\n<p>\u964d\u7ea7<\/p>\n<p>\u670d\u52a1\u4e0d\u884c\u4e86&#xff0c;\u603b\u5f97\u7ed9\u7528\u6237\u4e00\u4e2a\u4ea4\u4ee3\u3002<\/p>\n<p>\u964d\u7ea7\u5c31\u662fPlan B\u3002\u6b63\u5e38\u65b9\u6848\u8d70\u4e0d\u901a&#xff0c;\u8d70\u5907\u9009\u65b9\u6848\u3002<\/p>\n<p>\u6bd4\u5982\u5546\u54c1\u670d\u52a1\u6302\u4e86&#xff0c;\u5546\u54c1\u8be6\u60c5\u9875\u603b\u4e0d\u80fd\u767d\u5c4f\u5427&#xff1f;\u8fd4\u56de\u4e2a\u201d\u5546\u54c1\u4fe1\u606f\u52a0\u8f7d\u4e2d\u2026\u201c&#xff0c;\u8d77\u7801\u9875\u9762\u80fd\u5c55\u793a\u3002<\/p>\n<p>\u6216\u8005\u8fd4\u56de\u4e4b\u524d\u7f13\u5b58\u7684\u6570\u636e&#xff0c;\u6570\u636e\u53ef\u80fd\u4e0d\u662f\u6700\u65b0\u7684&#xff0c;\u4f46\u603b\u6bd4\u6ca1\u6709\u5f3a\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u79cd\u662f\u529f\u80fd\u964d\u7ea7\u3002\u53cc\u5341\u4e00\u7684\u65f6\u5019\u628a\u9000\u6b3e\u529f\u80fd\u76f4\u63a5\u5173\u6389&#xff0c;\u6240\u6709\u8d44\u6e90\u4fdd\u4ea4\u6613&#xff0c;\u8fd9\u4e5f\u662f\u964d\u7ea7\u3002<\/p>\n<p>\u9996\u9875\u63a8\u8350\u4f4d\u4e5f\u662f&#xff0c;\u63a8\u8350\u670d\u52a1\u6302\u4e86\u5c31\u5c55\u793a\u63d0\u524d\u51c6\u5907\u597d\u7684\u70ed\u95e8\u5546\u54c1&#xff0c;\u7528\u6237\u6839\u672c\u611f\u77e5\u4e0d\u5230\u3002<\/p>\n<p>\u4e09\u8005\u5565\u5173\u7cfb<\/p>\n<p>\u753b\u4e2a\u56fe\u5c31\u6e05\u695a\u4e86&#xff1a;<\/p>\n<p>\u4f60\u7684\u670d\u52a1<br \/>\n                            \u2502<br \/>\n  \u8bf7\u6c42\u8fdb\u6765 \u2500\u2500\u25b6 [\u9650\u6d41] \u2500\u2500\u25b6 \u4e1a\u52a1\u5904\u7406 \u2500\u2500\u25b6 [\u7194\u65ad] \u2500\u2500\u25b6 \u8c03\u4e0b\u6e38<br \/>\n                \u2502                        \u2502<br \/>\n                \u2502 \u8d85\u4e86                   \u2502 \u4e0b\u6e38\u6302\u4e86<br \/>\n                \u25bc                        \u25bc<br \/>\n             [\u964d\u7ea7]                   [\u964d\u7ea7]<br \/>\n            \u8fd4\u56de\u515c\u5e95                  \u8fd4\u56de\u515c\u5e95<\/p>\n<p>\u9650\u6d41\u5728\u5165\u53e3&#xff0c;\u63a7\u5236\u8fdb\u6765\u591a\u5c11\u6d41\u91cf&#xff0c;\u4fdd\u62a4\u81ea\u5df1\u3002\u7194\u65ad\u5728\u51fa\u53e3&#xff0c;\u8c03\u522b\u4eba\u4e4b\u524d\u5224\u65ad\u4e00\u4e0b&#xff0c;\u522b\u4eba\u6302\u4e86\u5c31\u522b\u8c03\u4e86\u3002\u964d\u7ea7\u662f\u515c\u5e95&#xff0c;\u4e0d\u7ba1\u54ea\u91cc\u51fa\u95ee\u9898&#xff0c;\u90fd\u5f97\u6709\u4e2a\u5907\u9009\u65b9\u6848\u3002<\/p>\n<p>\u4e09\u4e2a\u4e0d\u662f\u4e92\u65a5\u7684&#xff0c;\u662f\u914d\u5408\u7528\u7684\u3002\u4e00\u4e2a\u8bf7\u6c42\u8fdb\u6765&#xff0c;\u5148\u8fc7\u9650\u6d41&#xff0c;\u7136\u540e\u5904\u7406\u4e1a\u52a1&#xff0c;\u8c03\u4e0b\u6e38\u524d\u8fc7\u7194\u65ad&#xff0c;\u4efb\u4f55\u73af\u8282\u51fa\u95ee\u9898\u90fd\u8d70\u964d\u7ea7\u3002<\/p>\n<hr \/>\n","protected":false},"excerpt":{"rendered":"<p>Mybatis<br \/>\n\u7f13\u5b58\u673a\u5236<br \/>\nMyBatis \u63d0\u4f9b\u4e86\u4e24\u7ea7\u7f13\u5b58\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002 \u4e00\u7ea7\u7f13\u5b58&#xff08;\u672c\u5730\u7f13\u5b58&#xff09;&#xff1a; \u4f5c\u7528\u8303\u56f4&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u662f\u5728SqlSession\u7684\u751f\u547d\u5468\u671f\u5185\u6709\u6548&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bcf\u4e2aSqlSession\u62e5\u6709\u72ec\u7acb\u7684\u4e00\u7ea7\u7f13\u5b58\u3002\u9ed8\u8ba4\u5f00\u542f&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u5728MyBatis\u4e2d\u9ed8\u8ba4\u662f\u5f00\u542f\u7684&#xff0c;\u65e0\u9700\u989d\u5916\u914d\u7f6e\u3002\u7279\u70b9&#xff1a; \u5f53\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6&#xff0c;\u67e5\u8be2\u7684\u7ed3\u679c\u4f1a\u88ab\u7f13\u5b58\u5728\u5f53\u524dSq<\/p>\n","protected":false},"author":2,"featured_media":66844,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,101,292],"topic":[],"class_list":["post-66850","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-spring","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/66850.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"Mybatis \u7f13\u5b58\u673a\u5236 MyBatis \u63d0\u4f9b\u4e86\u4e24\u7ea7\u7f13\u5b58\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002 \u4e00\u7ea7\u7f13\u5b58&#xff08;\u672c\u5730\u7f13\u5b58&#xff09;&#xff1a; \u4f5c\u7528\u8303\u56f4&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u662f\u5728SqlSession\u7684\u751f\u547d\u5468\u671f\u5185\u6709\u6548&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bcf\u4e2aSqlSession\u62e5\u6709\u72ec\u7acb\u7684\u4e00\u7ea7\u7f13\u5b58\u3002\u9ed8\u8ba4\u5f00\u542f&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u5728MyBatis\u4e2d\u9ed8\u8ba4\u662f\u5f00\u542f\u7684&#xff0c;\u65e0\u9700\u989d\u5916\u914d\u7f6e\u3002\u7279\u70b9&#xff1a; \u5f53\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6&#xff0c;\u67e5\u8be2\u7684\u7ed3\u679c\u4f1a\u88ab\u7f13\u5b58\u5728\u5f53\u524dSq\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/66850.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-01-27T10:17:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101726-697890b60693b.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/66850.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/66850.html\",\"name\":\"Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-27T10:17:30+00:00\",\"dateModified\":\"2026-01-27T10:17:30+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/66850.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/66850.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/66850.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring\u5168\u5bb6\u6876\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/66850.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"Mybatis \u7f13\u5b58\u673a\u5236 MyBatis \u63d0\u4f9b\u4e86\u4e24\u7ea7\u7f13\u5b58\u6765\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u3002 \u4e00\u7ea7\u7f13\u5b58&#xff08;\u672c\u5730\u7f13\u5b58&#xff09;&#xff1a; \u4f5c\u7528\u8303\u56f4&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u662f\u5728SqlSession\u7684\u751f\u547d\u5468\u671f\u5185\u6709\u6548&#xff0c;\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6bcf\u4e2aSqlSession\u62e5\u6709\u72ec\u7acb\u7684\u4e00\u7ea7\u7f13\u5b58\u3002\u9ed8\u8ba4\u5f00\u542f&#xff1a; \u4e00\u7ea7\u7f13\u5b58\u5728MyBatis\u4e2d\u9ed8\u8ba4\u662f\u5f00\u542f\u7684&#xff0c;\u65e0\u9700\u989d\u5916\u914d\u7f6e\u3002\u7279\u70b9&#xff1a; \u5f53\u6267\u884c\u67e5\u8be2\u64cd\u4f5c\u65f6&#xff0c;\u67e5\u8be2\u7684\u7ed3\u679c\u4f1a\u88ab\u7f13\u5b58\u5728\u5f53\u524dSq","og_url":"https:\/\/www.wsisp.com\/helps\/66850.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-27T10:17:30+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/01\/20260127101726-697890b60693b.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"14 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/66850.html","url":"https:\/\/www.wsisp.com\/helps\/66850.html","name":"Spring\u5168\u5bb6\u6876 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-27T10:17:30+00:00","dateModified":"2026-01-27T10:17:30+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/66850.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/66850.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/66850.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring\u5168\u5bb6\u6876"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/66850","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=66850"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/66850\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/66844"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=66850"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=66850"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=66850"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=66850"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}