{"id":202552,"date":"2025-05-22T09:59:12","date_gmt":"2025-05-22T01:59:12","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202552\/"},"modified":"2025-05-22T09:59:12","modified_gmt":"2025-05-22T01:59:12","slug":"spring-boot%e4%b8%ad%e7%9a%84%e5%be%aa%e7%8e%af%e4%be%9d%e8%b5%96","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202552\/","title":{"rendered":"Spring Boot\u4e2d\u7684\u5faa\u73af\u4f9d\u8d56"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Spring Boot\u4e2d\u7684\u5faa\u73af\u4f9d\u8d56<\/h1>\n<p><span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span>    <\/p>\n<p>\u5728IT\u884c\u4e1a\u8fd9\u4e2a\u53d1\u5c55\u66f4\u65b0\u901f\u5ea6\u5f88\u5feb\u7684\u884c\u4e1a\uff0c\u53ea\u6709\u4e0d\u505c\u6b62\u7684\u5b66\u4e60\uff0c\u624d\u4e0d\u4f1a\u88ab\u884c\u4e1a\u6240\u6dd8\u6c70\u3002\u5982\u679c\u4f60\u662f\u6587\u7ae0\u5b66\u4e60\u8005\uff0c\u90a3\u4e48\u672c\u6587\u300aSpring Boot\u4e2d\u7684\u5faa\u73af\u4f9d\u8d56\u300b\u5c31\u5f88\u9002\u5408\u4f60\uff01\u672c\u7bc7\u5185\u5bb9\u4e3b\u8981\u5305\u62ec##content_title##\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u7684\u77e5\u8bc6\u79ef\u7d2f\u6709\u6240\u5e2e\u52a9\uff0c\u52a9\u529b\u5b9e\u6218\u5f00\u53d1\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729916882671c6fd25325e.jpg\" style=\"max-width:100%\" class=\"aligncenter\"><\/p>\n<p>java \u4e2d\u7684\u5faa\u73af\u4f9d\u8d56\u662f\u6307\u4e24\u4e2a\u7c7b\u6216\u4e24\u4e2a\u6a21\u5757\u76f8\u4e92\u4f9d\u8d56\uff0c\u4ece\u800c\u5f62\u6210\u5faa\u73af\u3002<\/p>\n<p>\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u76f8\u4e92\u4f9d\u8d56\u7684 bean a \u548c b\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n<pre>@component\npublic class a{\n    private final b b;\n    public a(b b){\n        this.b = b;\n    }\n}\n<\/pre>\n<pre>@component\npublic class b{\n    private final a a;\n    public b(a a){\n        this.a = a;\n    }\n}\n<\/pre>\n<p>\u8fd0\u884c\u9879\u76ee\u65f6\uff0c\u4f1a\u51fa\u73b0\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>relying upon circular references is discouraged and they are prohibited by default. update your application to remove the dependency cycle between beans. as a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.\n<\/pre>\n<p>\u56e0\u6b64\uff0c\u4e3a\u4e86\u89e3\u51b3\u8fd9\u79cd\u5faa\u73af\u4f9d\u8d56\uff0c\u6211\u4eec\u6709\u56db\u79cd\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u91cd\u6784\u4ee3\u7801\u4ee5\u5206\u79bb\u804c\u8d23\u3002<\/li>\n<li>\u4f7f\u7528\u4e2d\u95f4\u7c7b\u6216\u63a5\u53e3\u3002<\/li>\n<li>\u901a\u8fc7\u65b9\u6cd5\uff08setter\uff09\u5e94\u7528\u4f9d\u8d56\u6ce8\u5165\u3002<\/li>\n<li>\u4f7f\u7528 @lazy \u7b49\u6ce8\u89e3\u6765\u5ef6\u8fdf\u521d\u59cb\u5316\u3002<\/li>\n<\/ul>\n<p>\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u7b2c\u56db\u79cd\u89e3\u51b3\u65b9\u6848\uff0c\u5373\u4f7f\u7528\u6ce8\u91ca<strong>@lazy<\/strong>\uff0c\u5982\u4e0b\u4f8b\u6240\u793a\uff1a<\/p>\n<pre>@component\npublic class a{\n    private final b b;\n    public a(@lazy b b){\n        this.b = b;\n    }\n}\n<\/pre>\n<pre>@component\npublic class b{\n    private final a a;\n    public b(a a){\n        this.a = a;\n    }\n}\n<\/pre>\n<p>\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u8131\u79bb\u4e86\u8fd9\u4e2a\u5faa\u73af:)<\/p>\n<p>\u6587\u4e2d\u5173\u4e8e\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aSpring Boot\u4e2d\u7684\u5faa\u73af\u4f9d\u8d56\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spring Boot\u4e2d\u7684\u5faa\u73af\u4f9d&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202552","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202552","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202552"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202552\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202552"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202552"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202552"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}