{"id":167084,"date":"2020-10-07T17:57:15","date_gmt":"2020-10-07T09:57:15","guid":{"rendered":"http:\/\/4563.org\/?p=167084"},"modified":"2020-10-07T17:57:15","modified_gmt":"2020-10-07T09:57:15","slug":"autowired-%e6%b3%a8%e5%85%a5%e8%bd%ac%e6%8d%a2%e4%b8%ba%e6%9e%84%e9%80%a0%e5%99%a8%e6%b3%a8%e5%85%a5%ef%bc%8c%e5%af%bc%e8%87%b4%e7%9a%84%e6%9e%84%e9%80%a0%e5%99%a8%e4%bb%a3%e7%a0%81%e8%87%83%e8%82%bf","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=167084","title":{"rendered":"@Autowired \u6ce8\u5165\u8f6c\u6362\u4e3a\u6784\u9020\u5668\u6ce8\u5165\uff0c\u5bfc\u81f4\u7684\u6784\u9020\u5668\u4ee3\u7801\u81c3\u80bf\uff0c\u9664\u4e86 Lombok \u5916\u8fd8\u6709\u522b\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  @Autowired \u6ce8\u5165\u8f6c\u6362\u4e3a\u6784\u9020\u5668\u6ce8\u5165\uff0c\u5bfc\u81f4\u7684\u6784\u9020\u5668\u4ee3\u7801\u81c3\u80bf\uff0c\u9664\u4e86 Lombok \u5916\u8fd8\u6709\u522b\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vate32 <\/span>  <span><i><\/i> 4<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u5404\u535a\u5ba2\u6587\u7ae0\u8bf4\u7684\u90fd\u662f\u8981\u4e48\u4f7f\u7528 Lombok \u7684 @ RequiredArgsConstructor \u6ce8\u89e3\uff0c\u8981\u4e48\u201c\u8003\u8651\u8fd9\u4e2a\u7c7b\u662f\u7b26\u5408\u8db3\u5355\u4e00\u804c\u8d23\u539f\u5219\u4e86\uff0c\u5c06\u8fd9\u4e2a\u7c7b\u62c6\u5206\u4e3a\u591a\u4e2a\u7c7b\u201d\u3002\u53ef\u662f\u5bf9\u4e8e\u524d\u8005\uff0c\u9879\u76ee\u4e0d\u4e00\u5b9a\u4f7f\u7528 Lombok\uff0c\u5bf9\u4e8e\u540e\u8005\uff0c\u5b9e\u9645\u4e1a\u52a1\u60c5\u51b5\u53ef\u80fd\u4f7f\u7528\u5f88\u591a\u4e2a\u4f9d\u8d56\u7c7b\uff0c\u62c6\u5206\u4e0d\u592a\u73b0\u5b9e\u3002\u8bf7\u95ee\u8fd8\u6709\u522b\u7684\u4f18\u96c5\u7684\u89e3\u51b3\u65b9\u6848\u5417\uff1f      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>27<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"3690141\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3a\u4ec0\u4e48\u8981\u6362\uff0c@Autowired \u4e0d\u9999\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690142\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lychs1998 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NULL2020 \u6784\u9020\u5668\u6ce8\u5165\u4e5f\u662f @Autowired \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690143\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : vate32 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NULL2020 \u4f7f\u7528 Autowired \u8fdb\u884c\u6ce8\u5165\u6709\u7a7a\u6307\u9488\u98ce\u9669\uff08\u4f8b\u5982\u5728\u6784\u9020\u51fd\u6570\u91cc\u4f7f\u7528\u4e86\u6ce8\u5165\u7684\u5bf9\u8c61\uff0c\u4f46\u662f\u6784\u9020\u51fd\u6570\u7684\u8c03\u7528\u4f18\u5148\u4e8e\u81ea\u52a8\u6ce8\u5165\uff0c\u6b64\u65f6\u8c03\u7528\u5c31\u4f1a\u629b\u51fa\u7a7a\u6307\u9488\u9519\u8bef\uff09\uff0c\u4e5f\u4e0d\u65b9\u4fbf\u8fdb\u884c\u6d4b\u8bd5\uff0cSpring \u5b98\u65b9\u4e5f\u4e0d\u63a8\u8350\u4f7f\u7528\uff08 Spring Team recommends &#8220;Always use constructor based dependency injection in your beans. Always use assertions for mandatory dependencies&#8221;.\uff09\u3002\u8bdd\u8bf4\u5e73\u5e38 IDE \u7684\u8b66\u544a\u4f60\u4eec\u90fd\u4e0d\u770b\u7684\u5417                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690144\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : vantis <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5fc3\u60c5\u597d\u5c31\u53bb\u6539\u6539 \u5982\u679c\u662f\u522b\u4eba\u4ee3\u7801\u6211\u5c31\u4e0d\u52a8<br \/>(\u7a0b\u5e8f\u5458\u600e\u4e48\u56de\u53bb\u770b WARNING 233)                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690145\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NULL2020 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u89c4\u5219\u662f\u6b7b\u7684\uff0c\u4eba\u662f\u6d3b\u7684\uff0c\u600e\u4e48\u987a\u624b\u600e\u4e48\u6765                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690146\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : intmax2147483647 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NULL2020 \u987a\u624b\u5199\u4e00\u4e2a BUG                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690147\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : gdtdpt <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u573a\u666f\u5427\uff0c\u4e5f\u4e0d\u662f\u8bf4\u4e00\u5b9a\u4e0d\u80fd\u7528\u975e\u6784\u9020\u5668\u6ce8\u5165\u7684\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u786e\u5b9e\u9700\u8981\u5728\u4e00\u4e2a bean \u7684\u6784\u9020\u51fd\u6570\u4e2d\u505a\u4e9b\u4ec0\u4e48\uff0c\u624d\u9700\u8981\u628a\u76f8\u5173\u7684 bean \u4ee5\u6784\u9020\u5668\u6ce8\u5165\u7684\u65b9\u5f0f\u6ce8\u5165\u5230\u5f53\u524d\u5b9e\u4f8b\u3002<br \/>\u5982\u679c\u4e0d\u60f3\u8fd9\u6837\uff0c\u90a3\u4e5f\u53ef\u4ee5\u6ce8\u5165 ApplicationContext\uff0c\u5177\u4f53\u9700\u8981\u7684 Bean \u53ef\u4ee5\u4ece ApplicationContext \u4e2d\u83b7\u53d6\uff0c\u4f46\u662f\u8fd9\u6837\u505a\u4e5f\u6709\u53ef\u80fd\u83b7\u53d6\u7684 Bean \u4e3a null \u3002<br \/>\u6240\u4ee5\u6211\u89c9\u5f97\u5982\u679c\u6ca1\u9047\u5230\u6ce8\u5165\u7684 Bean \u4e3a null \u7684\u60c5\u51b5\u4e0b\uff0csetter \u6ce8\u5165\uff0cfield \u6ce8\u5165\u8fd8\u662f constructor \u6ce8\u5165\u4e09\u79cd\u65b9\u5f0f\u4e0d\u5fc5\u592a\u7ea0\u7ed3\uff0c\u5f53\u771f\u6b63\u9047\u5230\u4e86\u95ee\u9898\u518d\u53bb\u5206\u6790 bean \u7684 \u751f\u6210\u987a\u5e8f\u548c\u4ee3\u7801\u7684\u6267\u884c\u987a\u5e8f\u6bd4\u8f83\u597d\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690148\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Jooooooooo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u81c3\u80bf\u7684\u7f3a\u70b9\u662f?                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690149\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : hpashencedany1 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u62c6\u5427, \u6211\u5728\u6162\u6162\u62c6                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690150\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sheng3233386 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4eec\u90fd\u7528 @Resource                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690151\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Resource <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sheng3233386 #10 \u8c22\u9080                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690152\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Boyce <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Resource \u54c8\u54c8\u54c8\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690153\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chendy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u611f\u89c9\u8fd9\u4e2a\u6ce8\u5165\u5c31\u662f\u914d\u5408 lombok \u6700\u8212\u670d<br \/>\u4e0d\u8fc7\u786e\u5b9e\u6709\u4e9b\u573a\u666f\u4e0d\u80fd\u7528\uff0c\u6bd4\u5982 RestTemplateBuilder \u8fd9\u79cd<br \/>\u4e0d\u8fc7\u53cd\u6b63\u53ef\u4ee5\u81ea\u52a8\u751f\u6210\u81ea\u52a8\u8865\u5168<br \/>\u5982\u679c\u4e00\u4e2a bean \u8981\u6ce8\u5165\u7684 bean \u592a\u591a\u4e86\uff0c\u8003\u8651\u91cd\u6784\u4e00\u4e0b\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690154\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xiangyuecn <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Resource \u8fd9\u4e2a\u6ce8\u89e3\u786e\u5b9e\u725b\u903c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690155\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : MatthewHan <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NULL2020 #1 Autowired \u90fd\u8981\u88ab\u6dd8\u6c70\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690156\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : vate32 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Jooooooooo \u81ed\u957f\u81ed\u957f\u7684\uff0c\u6784\u9020\u51fd\u6570\u53c2\u6570\u5217\u8868\u5f88\u957f\uff0c\u4e0d\u597d\u7ef4\u62a4\uff08\u4e2a\u4eba\u89c2\u70b9\uff09\u3002<\/p>\n<p>@sheng3233386 \u76f4\u63a5\u4f7f\u7528\u540d\u79f0\u7684\u5417\uff0c\u4f46\u662f\u8fd9\u4e2a\u80fd\u591f\u907f\u514d\u4e0a\u9762\u8bf4\u7684\u7a7a\u6307\u9488\u9519\u8bef\u5417\uff0c\u597d\u50cf\u8ddf\u76f4\u63a5\u4f7f\u7528 autowired \u662f\u4e00\u6837\u7684\u3002<\/p>\n<p>@chendy \u5199\u7740\u7740\u5b9e\u5f88\u723d\uff0c\u4f46\u662f\u62c5\u5fc3\u6709\u7684\u5730\u65b9\u4e0d\u8ba9\u7528 Lombok \uff08\u4f3c\u4e4e\u60f3\u591a\u4e86\uff09<\/p>\n<p>@gdtdpt \u591a\u8c22\u5927\u4f6c\u6307\u70b9\uff0c\u8fd8\u662f\u5f97\u770b\u5b9e\u9645\u60c5\u51b5\u6765\u3002\u4ece ApplicationContext \u83b7\u53d6\u5230 Bean \u7684\u65b9\u6cd5\u8fd8\u6ca1\u7528\u5230\u8fc7\uff0c\u53bb\u5b66\u4e60\u4e00\u4e0b\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690157\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yuhaoyang222 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5efa\u9020\u8005\u6a21\u5f0f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690158\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : STRRL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u6e05\u695a lz \u8fd9\u4e2a\u95ee\u9898\u662f\u5728\u521a\u521a\u60f3\u505a\u8fd8\u662f\u5df2\u7ecf\u505a\u4e00\u6bb5\u65f6\u95f4\u4e86\uff0c\u4e0d\u77e5\u9053\u6709\u6ca1\u6709\u9047\u5230\u8fc7\u5faa\u73af\u4f9d\u8d56\u7684\u95ee\u9898\u3002<\/p>\n<p>constructor \u6ce8\u5165\u9700\u8981\u4f60\u5148\u6709\u4e00\u4e2a constructor\uff0c \u6240\u4ee5\u624b\u5199\u4e00\u4e2a\u4e5f\u597d lombok \u751f\u6210\u4e00\u4e2a\u4e5f\u597d\uff0c\u8fd8\u662f IDEA command+N generate \u4e00\u4e2a\u4e5f\u597d\uff0c\u90fd\u662f\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<p>\u6211 jio \u5f97\u5faa\u73af\u4f9d\u8d56\u624d\u662f\u65e0\u6cd5\u4f7f\u7528 constructor \u6ce8\u5165\u7684\u7f6a\u9b41\u7978\u9996\uff0c\u6bd5\u7adf\u5373\u4f7f\u4f60\u7684 constructor \u9700\u8981\u7684\u53c2\u6570\u518d\u591a\uff0c\u4e5f\u5c31\u662f\u4e00\u4e2a\u6ce8\u89e3\u6216\u8005\u4e00\u4e2a\u5feb\u6377\u952e\u81ea\u52a8\u751f\u6210\u7684\u4e8b\u3002\u7531\u4e8e\u8bbe\u8ba1\u4e0a\u7684\u5931\u8bef\u5bfc\u81f4\u7684\u5faa\u73af\u4f9d\u8d56\u4f1a\u4f7f\u4f60\u538b\u6839\u7528\u4e0d\u4e86\u6784\u9020\u5668\u6ce8\u5165\uff0c\u800c\u4e14\u6709\u5faa\u73af\u4f9d\u8d56\u7684\u9879\u76ee\u591a\u591a\u5c11\u5c11\u4f1a\u6709\u5176\u4ed6\u7684 badsmell &#8230;\uff08\u7834\u7a97\u3002\u3002\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690159\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : linvaux <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u516c\u53f8\u7981\u6b62\u4f7f\u7528 lombok\uff0c\u800c\u4e14\uff0c\u8fd9\u73a9\u610f\u513f\u4ee3\u7801\u80fd\u6709\u591a\u5197\u4f59\uff1f\u53ea\u662f\u81ea\u5df1\u5f3a\u8feb\u75c7\u53d1\u4f5c\u4e86\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690160\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Aresxue <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e00\u822c\u65e0\u975e\u5c31\u8fd8\u662f\u63d2\u4ef6, idea \u5b98\u65b9\u80fd\u51fa\u4e2a\u529f\u80fd\u662f\u6700\u597d\u7684\uff0c\u867d\u7136\u6784\u9020\u5668\u66f4\u597d\u4f46\u5982\u679c\u6ca1\u6709\u5176\u4ed6\u914d\u5408\u8fd8\u662f\u7528 field \u6ce8\u5165\u5427\uff0c\u81f3\u5c11\u4e0d\u7528\u5728\u65b0\u52a0\u670d\u52a1\u540e\u8fd8\u8981\u6539\u6784\u9020\u5668                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690161\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wallfacers <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lychs1998 \u6784\u9020\u5668\u6ce8\u5165\u4e0d\u662f @Autowired\uff0c\u4e24\u8005\u5b9e\u73b0\u533a\u522b\u5f88\u5927\u3002 @Autowired \u662f\u901a\u8fc7 AutowiredAnnotationBeanPostProcessor \u8fdb\u884c\u6ce8\u5165\u7684\uff0c\u800c\u6784\u9020\u5668\u6ce8\u5165\u662f\u5728 Bean \u7684\u521b\u5efa\u9636\u6bb5\uff0c\u5c31\u4f1a\u53bb\u627e\u5230\u6700\u5339\u914d\u7684\u6784\u9020\u5668\uff0c\u5e76\u4e14\u51c6\u5907\u597d\u6784\u9020\u5668\u9700\u8981\u4f9d\u8d56\u7684 Bean                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690162\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ic2y <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @vate32 Autowired \u6ce8\u5165\u5728\u591a\u4eba\u5927\u578b\u9879\u76ee\u91cc\uff0c\u6211\u78b0\u5230\u8fc7\u4e00\u4e9b\u95ee\u9898\uff0c\u56e0\u4e3a\u56e2\u961f\u6210\u5458\u7684\u7406\u89e3\u4e0d\u4e00\u6837\uff1a\u5bb9\u6613\u9020\u6210\u6ee5\u7528\uff08\u53ef\u80fd\u662f\u4e3a\u4e86\u590d\u7528\u67d0\u4e2a\u80fd\u529b\uff0c\u5c31\u6ce8\u5165\u4e00\u5806 bean \uff09\u3001\u5faa\u73af\u4f9d\u8d56\uff08\u5e95\u5c42\u6a21\u578b\u6ce8\u5165\u4e86\u9ad8\u5c42\u6a21\u578b\u7684 bean\uff0c\u53ef\u80fd\u4ea4\u53c9\uff09\u3001\u591a\u6a21\u5757\u7684\u9879\u76ee\u5f88\u96be\u7ba1\u7406\uff08\u6709\u79cd\u62d4\u51fa\u841d\u535c\u5e26\u51fa\u6ce5\u7684\u611f\u89c9\uff0c\u56e0\u4e3a A \u548c B \u9879\u76ee\u5171\u4eab\u4e86\u6a21\u5757 C\uff0cB \u9879\u76ee\u5728 C \u6a21\u5757\u589e\u52a0\u4e86\u4e00\u4e2a Autowired \u6ce8\u5165\uff0cA \u9879\u76ee\u6ca1\u6709\u611f\u77e5\uff09\u3002<\/p>\n<p>\u6211\u81ea\u5df1\u8ba4\u4e3a\uff0c\u6784\u9020\u5668\u6ce8\u5165\u66f4\u597d\uff0cSpring \u5b98\u65b9\u4e5f\u63a8\u8350\uff0c\u6784\u9020\u5668\u6ce8\u5165\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\uff1a\u5f3a\u8feb\u5f00\u53d1\u8005\u53bb\u601d\u8003\uff0c\u5f53\u524d\u7684 bean \u4e3a\u4ec0\u4e48\u8981\u6ce8\u5165\u5176\u4ed6\u7684\u4f9d\u8d56\u3002<\/p>\n<p>\u5982\u679c\u4f60\u7528\u4e86 Lombok \u81ea\u52a8\u5b9e\u73b0\u4e86\u6784\u9020\u5668\u6ce8\u5165\uff0c\u90a3\u4e48\u8fd9\u79cd\u5f3a\u8feb\u5f00\u53d1\u8005\u53bb\u601d\u8003\u7684\u52a8\u673a\u5c31\u6ca1\u6709\u4e86\uff0c\u8fd8\u4e0d\u5982\u76f4\u63a5 Autowired \u3002<\/p>\n<p>\u624b\u52a8\u7684\u7528\u6784\u9020\u5668\u6ce8\u5165\uff08\u9664\u4e86\u67d0\u4e9b\u7279\u5b9a\u7684\u7c7b\uff0c\u4f8b\u5982 Controller \u4e4b\u7c7b\u7684\uff09\uff0c\u6211\u8ba4\u4e3a\u6709\u5982\u4e0b\u4f18\u70b9\uff1a<br \/>1.\u5f3a\u8feb\u6211\u81ea\u5df1\u601d\u8003\uff1a\u8fd9\u4e2a\u6ce8\u5165\u662f\u5426\u662f\u5fc5\u987b\u7684\uff0c\u662f\u5426\u53ef\u4ee5\u7528\u5de5\u5177\u7c7b\uff1f\u7528\u8bbe\u8ba1\u6a21\u5f0f\uff1f\u6216\u8005\u5176\u4ed6\u7684\u4f18\u96c5\u65b9\u6cd5\u6765\u5b9e\u73b0\u8fd9\u4e2a\u903b\u8f91\u8bbe\u8ba1\u3002<br \/>2.\u6ce8\u5165\u7684\u6539\u53d8\u662f\u53ef\u611f\u77e5\u7684\u3002\u5728\u5927\u578b\u591a\u6a21\u5757\u67b6\u6784\u7684\u534f\u4f5c\u5de5\u7a0b\u91cc\uff0c\u53ef\u80fd\u5f88\u6709\u7528\u3002\u5927\u5bb6\u5728\u534f\u4f5c\u91cc\u590d\u7528\u4e86\u6a21\u5757 C\uff0c\u4e00\u65e6\u4f60\u5728\u6a21\u5757\u91cc\u589e\u52a0\u4e86\u6ce8\u5165\u53c2\u6570\uff0c\u90a3\u4e48\u5176\u4ed6\u4eba\u7528\u5230\u4e86\u6a21\u5757 C \u6ce8\u5165 bean\uff0c\u4f1a\u7acb\u523b\u7f16\u8bd1\u9519\u8bef\u3002<br \/>3.\u56e0\u4e3a\u5927\u578b\u5de5\u7a0b\u91cc\uff0c\u4e00\u822c\u4f1a\u628a\u67d0\u4e2a\u6a21\u5757\u4f5c\u4e3a\u4e00\u4e2a jar \u5305\uff0c\u8ba9\u5176\u4ed6\u5e94\u7528\u5f15\u7528\uff0cConfiguration \u91cc\u52a8\u6001\u58f0\u660e Bean \u7684\u65f6\u5019\uff0c\u611f\u89c9\u66f4\u4ece\u5bb9\u3002\u56e0\u4e3a\u6211\u77e5\u9053\u5f53\u524d\u7684 bean \u6240\u6709\u7684\u4f9d\u8d56\u90fd\u662f\u6784\u9020\u65b9\u5f0f\u6ce8\u5165\uff0c\u6211\u53ef\u4ee5\u4ece\u5bb9\u9009\u62e9\u4e00\u7ec4\u81ea\u5df1\u6307\u5b9a\u7684 bean \u8fdb\u53bb\u7ec4\u88c5\u3002<br \/>4.\u67d0\u79cd\u610f\u4e49\u4e0a\uff0c\u5b9e\u73b0\u4e86\u4e1a\u52a1\u4ee3\u7801\u548c Spring \u6846\u67b6\u7684\u89e3\u8026\u3002\u56e0\u4e3a\u6784\u9020\u5668\u6ce8\u5165\u7684\u8bdd\uff0c\u5c31\u50cf\u5728\u5199\u666e\u901a\u7684 java \u7684 pojo \u3002\u6211\u4eec\u4e0d\u9700\u8981 @Autowired \u4e0d\u9700\u8981 @Service \u548c @Component\uff0c\u4e1a\u52a1\u7c7b\u91cc\u57fa\u672c\u4e0d\u4f1a import spring \u7684\u4e1c\u897f\uff0c\u4f9d\u8d56 Configuration \u7684\u52a8\u6001\u88c5\u914d\u80fd\u529b\uff0c\u4ece\u6784\u9020\u6ce8\u5165\u58f0\u660e\u4e86\u4e00\u4e2a\u4e2a\u7684 bean\uff0c\u5b8c\u5168\u53ef\u63a7\uff08\u9002\u5408\u6709\u6d01\u7656\u7684\u4eba\uff09\u3002\u5982\u679c\u6709\u573a\u666f\uff0c\u9700\u8981\u79fb\u690d\u7684\u8bdd\uff0c\u4f1a\u5f88\u5bb9\u6613\uff0c\u4f8b\u5982\uff1a\u4ece Spring \u6846\u67b6\u79fb\u690d\u5230 google \u7684 guice \u6846\u67b6\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u5982\u679c\u6784\u9020\u5668\u6ce8\u5165\u7684 bean \u5f88\u591a\u7684\u65f6\u5019\uff0c\u4e5f\u662f\u4e00\u4e2a\u5f3a\u8feb\u6027\u7684\u63d0\u9192:\u662f\u5b9e\u65f6\u601d\u8003\u5f53\u524d\u7684 bean \u7684\u8bbe\u8ba1\u95ee\u9898\u4e86\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690163\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wysnylc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6784\u9020\u5668\u65e0\u6cd5\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u95ee\u9898,spring \u63a8\u8350\u6784\u9020\u5668\u6ce8\u5165\u540c\u65f6\u4e5f\u8bf4\u4e86\u8be5\u95ee\u9898<br \/>\u6ca1\u80fd\u529b\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u7684\u5c31\u522b\u778e\u6298\u817e                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690164\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : EminemW <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e0d\u53ef\u4ee5\u5b9e\u73b0 InitializingBean \u63a5\u53e3\u561b                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690165\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : br00k <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u63a8\u8350\u6784\u9020\u65b9\u6cd5\u6ce8\u5165\u3002IDE \u53ef\u4ee5\u6839\u636e\u5c5e\u6027\u81ea\u52a8\u751f\u6210\u6784\u9020\u65b9\u6cd5\u3002<br \/>\u56e0\u4e3a\u6784\u9020\u65b9\u6cd5\u6ce8\u5165\u9ed8\u8ba4\u662f\u4e0d\u80fd\u5faa\u73af\u5f15\u7528\uff0c\u5faa\u73af\u5f15\u7528\u66f4\u591a\u662f\u4ee3\u7801\u7ed3\u6784\u6216\u8bbe\u8ba1\u4e0d\u5408\u7406\uff0c\u8fd9\u6837\u80fd\u7ea6\u675f\u4f60\u7684\u4ee3\u7801\uff0c\u903c\u8feb\u4f60\u53bb\u601d\u8003\u907f\u514d\u5faa\u73af\u5f15\u7528\uff0c\u8fd9\u662f\u975e\u5e38\u597d\u7684\u3002<br \/>\u81f3\u4e8e\u8bf4\u975e\u8981\u5faa\u73af\u5f15\u7528\uff0c\u8bf7\u5728\u6784\u9020\u53c2\u6570\u4e0a\u4f7f\u7528 @Lazy \u5c31\u53ef\u4ee5\u4e86\u3002\u8fd9\u4e2a\u662f\u4e0d\u5efa\u8bae\u7684\uff0c\u5982\u679c\u90fd\u8fd9\u6837\u5199\uff0c\u8fd8\u4e0d\u5982\u7528 autowired \u3002<br \/>\u6211\u7684\u4e60\u60ef\u662f\u53ea\u6709\u5728 Bean \u81ea\u5df1\u6ce8\u5165\u81ea\u5df1\u624d\u4f1a\u7528 @Lazy\uff0c\u8fd9\u6837\u662f\u907f\u514d\u4f7f\u7528 this \u8c03\u7528\u5185\u90e8\u65b9\u6cd5 AOP \u5931\u6548\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690166\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 1194129822 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u73b0\u5728\u5927\u591a\u6570\u9879\u76ee\u8fd8\u662f Filed \u6ce8\u5165\uff0cspring3 \u63a8\u8350 setter \u6ce8\u5165\uff0c4 \u63a8\u8350\u6784\u9020\u5668\u6ce8\u5165\uff0c\u4e14 4.3 \u540e\u5982\u679c bean \u4e2d\u6709\u6784\u9020\u5668\uff0c\u5219\u4e0d\u9700\u8981 @Autowired, \u5c31\u5df2\u7ecf\u4f7f\u7528\u6784\u9020\u5668\u6ce8\u5165\uff0c\u590d\u6742\u7684\u662f spring \u6784\u9020\u5668\uff0csetter\uff0cFiled \u6ce8\u5165\u53ef\u4ee5\u4e00\u8d77\u5de5\u4f5c\uff0c\u6240\u4ee5\u4f60\u4f7f\u7528 Lombok\uff0c\u53ea\u8981\u7528\u4e86 AllArgsContructor\/RequiredArgsConstructor\uff0c\u5c31\u4e0d\u9700\u8981\u5176\u4ed6 spring \u6ce8\u89e3\u3002\u800c\u4e14\u6784\u9020\u5668\u6ce8\u5165\u65e0\u6cd5\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\uff0c\u800c\u4e14\u662f\u751f\u6210\u7684\u6784\u9020\u5668\uff0c\u4f60\u4e5f\u65e0\u6cd5\u64cd\u4f5c\uff0c\u6240\u4ee5 @Lazy \u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u4e0d\u53ef\u7528. \u4f46\u662f\u4f9d\u7136\u53ef\u4ee5\u5728\u9700\u8981\u5faa\u73af\u4f9d\u8d56\u7684 Bean \u4e0a\u4f7f\u7528 @Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)\u63d0\u524d\u66b4\u9732\u4ee3\u7406 Bean\uff0c\u4e0d\u8fc7 spring \u5b98\u65b9\u63a8\u8350\u6784\u9020\u5668\u6ce8\u5165\u7684\u539f\u56e0\u5c31\u662f\u7a0b\u5e8f\u5458\u81ea\u5df1\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"3690167\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sheng3233386 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @vate32 \u907f\u514d\u4e0d\u4e86\u7a7a\u6307\u9488\uff0c\u5728\u6784\u9020\u51fd\u6570\u7684\u8c03\u7528\u903b\u8f91\u5efa\u8bae\u5728 PostConstruct \u6ce8\u89e3\u7684\u65b9\u6cd5\u91cc\u6267\u884c\u3002Resource \u6ca1\u6709\u4f60\u8bf4\u7684 warning\uff0c\u54c8\u54c8                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>@Autowired \u6ce8\u5165\u8f6c\u6362\u4e3a\u6784&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167084"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167084"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/167084\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167084"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}