{"id":715,"date":"2023-05-28T02:11:04","date_gmt":"2023-05-27T18:11:04","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=715"},"modified":"2023-05-28T02:11:04","modified_gmt":"2023-05-27T18:11:04","slug":"spring-dependson%e6%b3%a8%e8%a7%a3%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-dependson%e6%b3%a8%e8%a7%a3%e8%a7%a3%e6%9e%90\/","title":{"rendered":"Spring @DependsOn\u6ce8\u89e3\u89e3\u6790"},"content":{"rendered":"<div class='wxsyncmain'>\n<section><mp-common-profile class=\"js_uneditable custom_select_card mp_profile_iframe\" data-pluginname=\"mpprofile\" data-weui-theme=\"light\" data-id=\"MzI3ODE5MzczNA==\" data-headimg=\"http:\/\/mmbiz.qpic.cn\/mmbiz_png\/OC2PjnBlMZjic6L6UHJXiaT0JCXiapkjUlh1wc5YRxBr1FvF4JB2kMibDia0m1vPHLtKr1BMxWm2QeGBRJhiaicbicw00w\/0?wx_fmt=png\" data-nickname=\"\u5218\u724c\" data-alias=\"\" data-signature=\"\u5bfb\u5e38\u7684\u74e6\u820d\u8bc4\u4e66\uff0c\u6697\u85cf\u7740\u6551\u4e16\u79d8\u8bc0\u3002\" data-from=\"0\" data-is_biz_ban=\"0\"><\/mp-common-profile><\/section>\n<section data-tool=\"mdnice\u7f16\u8f91\u5668\" data-website=\"https:\/\/www.mdnice.com\" style=\"color: black;line-height: 1.6;letter-spacing: 0px;word-break: break-word;overflow-wrap: break-word;text-align: left;font-size: 16px;padding: 10px;font-family: Optima-Regular, Optima, PingFangSC-light, PingFangTC-light, &quot;PingFang SC&quot;, Cambria, Cochin, Georgia, Times, &quot;Times New Roman&quot;, serif;\">\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 20px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 8px solid #ffbf52;\">\u4ecb\u7ecd<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u4eca\u5929\u8981\u5206\u4eab\u7684\u662fSpring\u7684@DependsOn\u6ce8\u89e3\uff0c\u5bf9\u4e8e@DependsOn\uff0c\u6211\u4eec\u4ece\u5b83\u7684\u540d\u79f0\u91cc\u9762\u5c31\u80fd\u770b\u51fa\u610f\u601d\u662f\u201c\u4f9d\u8d56\u4e8e\u201d\uff0c\u90a3\u4e48\u5728Spring\u4e2d\uff0c\u5b83\u7684\u4f5c\u7528\u5c31\u662f\u89e3\u51b3Bean\u7684\u521b\u5efa\u4f9d\u8d56\uff0c\u6bd4\u5982\u67d0\u4e2aBean\u5728\u521b\u5efa\u7684\u65f6\u5019\u4f9d\u8d56\u53e6\u5916\u4e00\u4e2abean\uff0c\u6240\u4ee5\u9700\u8981\u53e6\u5916\u4e00\u4e2abean\u5148\u521b\u5efa\uff0c\u7136\u540e\u518d\u521b\u5efa\u81ea\u5df1\u3002<\/p>\n<h2 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 22px;margin-top: 20px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 20px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 8px solid #ffbf52;\">\u6ce8\u89e3\u8be6\u60c5<\/span><\/h2>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">@DependsOn\u6ce8\u89e3\u53ef\u4ee5\u6807\u6ce8\u5728\u7c7b\u4e0a\u548c\u65b9\u6cd5\u4e0a\u9762\uff0c\u53ea\u6709\u4e00\u4e2a\u5c5e\u6027value\uff0c\u5b83\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u8868\u793a\u4f9d\u8d56\u7684bean\u540d\u79f0\u7684\u6570\u7ec4\uff0c\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u3002<\/p>\n<pre data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"margin-top: 10px;margin-bottom: 10px;border-radius: 5px;box-shadow: rgba(0, 0, 0, 0.55) 0px 2px 10px;\"><span style=\"display: block;background: url(&quot;https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015557643.jpeg&quot;) 10px 10px \/ 40px no-repeat rgb(40, 44, 52);height: 30px;width: 100%;margin-bottom: -7px;border-radius: 5px;\"><\/span><code style=\"overflow-x: auto;padding: 16px;color: #abb2bf;display: -webkit-box;font-family: Operator Mono, Consolas, Monaco, Menlo, monospace;font-size: 12px;-webkit-overflow-scrolling: touch;padding-top: 15px;background: #282c34;border-radius: 5px;\">&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">protected<\/span>&nbsp;&lt;T&gt;&nbsp;<span style=\"line-height: 26px;\">T&nbsp;<span style=\"color: #61aeee;line-height: 26px;\">doGetBean<\/span><span style=\"line-height: 26px;\">(String&nbsp;name,&nbsp;@Nullable&nbsp;Class&lt;T&gt;&nbsp;requiredType,&nbsp;@Nullable&nbsp;Object[]&nbsp;args,&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">boolean<\/span>&nbsp;typeCheckOnly)<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">throws<\/span>&nbsp;BeansException&nbsp;<\/span>{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;RootBeanDefinition&nbsp;mbd&nbsp;=&nbsp;getMergedLocalBeanDefinition(beanName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #5c6370;font-style: italic;line-height: 26px;\">\/\/&nbsp;Guarantee&nbsp;initialization&nbsp;of&nbsp;beans&nbsp;that&nbsp;the&nbsp;current&nbsp;bean&nbsp;depends&nbsp;on.<\/span><br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String[]&nbsp;dependsOn&nbsp;=&nbsp;mbd.getDependsOn();<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(dependsOn&nbsp;!=&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">null<\/span>)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">for<\/span>&nbsp;(String&nbsp;dep&nbsp;:&nbsp;dependsOn)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">if<\/span>&nbsp;(isDependent(beanName,&nbsp;dep))&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">throw<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">new<\/span>&nbsp;BeanCreationException(mbd.getResourceDescription(),&nbsp;beanName,<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"Circular&nbsp;depends-on&nbsp;relationship&nbsp;between&nbsp;'\"<\/span>&nbsp;+&nbsp;beanName&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"'&nbsp;and&nbsp;'\"<\/span>&nbsp;+&nbsp;dep&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"'\"<\/span>);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;registerDependentBean(dep,&nbsp;beanName);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">try<\/span>&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;getBean(dep);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">catch<\/span>&nbsp;(NoSuchBeanDefinitionException&nbsp;ex)&nbsp;{<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">throw<\/span>&nbsp;<span style=\"color: #c678dd;line-height: 26px;\">new<\/span>&nbsp;BeanCreationException(mbd.getResourceDescription(),&nbsp;beanName,<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"'\"<\/span>&nbsp;+&nbsp;beanName&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"'&nbsp;depends&nbsp;on&nbsp;missing&nbsp;bean&nbsp;'\"<\/span>&nbsp;+&nbsp;dep&nbsp;+&nbsp;<span style=\"color: #98c379;line-height: 26px;\">\"'\"<\/span>,&nbsp;ex);<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/>&nbsp;&nbsp;&nbsp;&nbsp;}<br  \/><\/code><\/pre>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u51fa\uff0c\u5176\u5b9e\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\uff0c\u4e3b\u8981\u5c31\u662f\u5224\u65ad\u662f\u5426\u6709\u4f9d\u8d56\u7684bean\uff0c\u5982\u679c\u6709\u5c31\u5148\u521b\u5efa\u4f9d\u8d56\u7684bean\uff0c\u6ca1\u6709\u7684\u8bdd\u5c31\u5f80\u4e0b\u6267\u884c\u3002<\/p>\n<h3 data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-weight: bold;font-size: 20px;margin-top: 15px;\"><span style=\"display: none;\"><\/span><span style=\"font-size: 18px;color: #f48a00;display: inline-block;padding-left: 10px;border-left: 4px solid #ffe3a3;\">\u603b\u7ed3<\/span><span style=\"display: none;\"><\/span><\/h3>\n<p data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"padding-top: 8px;padding-bottom: 8px;margin-top: 5px;margin-bottom: 5px;line-height: 1.75;letter-spacing: 0.1em;word-spacing: 0.1em;text-align: justify;color: rgba(0, 0, 0, 0.85);\">\u4e0a\u9762\u6211\u4eec\u5bf9@DependsOn\u4f5c\u4e86\u7b80\u5355\u7684\u4ecb\u7ecd\uff0c\u5bf9\u5176\u7684\u4f7f\u7528\u65b9\u6cd5\u8fdb\u884c\u7b80\u5355\u793a\u4f8b\uff0c\u4e5f\u5bf9\u6838\u5fc3\u6e90\u7801\u8fdb\u884c\u5206\u6790\uff0c\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\uff0c\u4ed6\u4eec\u90fd\u662fbean\u521b\u5efa\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e9b\u589e\u5f3a\uff0cspring\u7684\u521b\u5efa\u8fc7\u7a0b\u8fd8\u662f\u6bd4\u8f83\u7b80\u5355\uff0c\u4f46\u662f\u5c31\u662f\u56e0\u4e3a\u5b83\u7684\u529f\u80fd\u70b9\u6bd4\u8f83\u591a\uff0c\u6240\u4ee5\u5728\u521b\u5efa\u8fc7\u7a0b\u4e2d\u4f1a\u6709\u5404\u79cd\u6269\u5c55\uff0c\u5404\u79cd\u5224\u65ad\uff0c\u6240\u4ee5\u5c31\u4f1a\u53d8\u5f97\u5f88\u590d\u6742\uff0c\u4e0d\u8fc7\u5b83\u7684\u4e3b\u7ebf\u8fd8\u662f\u6bd4\u8f83\u6e05\u6670\u7684\uff0c\u5728\u8fdb\u884c\u5206\u6790\u7684\u65f6\u5019\uff0c\u53ef\u4ee5\u5148\u4ece\u4e3b\u7ebf\u8fdb\u884c\u5206\u6790\uff0c\u7136\u540e\u518d\u6162\u6162\u53bb\u770b\u4e3b\u7ebf\u5206\u51fa\u53bb\u7684\u903b\u8f91\u3002<\/p>\n<blockquote data-tool=\"mdnice\u7f16\u8f91\u5668\" style=\"font-size: 0.9em;overflow: auto;color: rgb(106, 115, 125);padding: 10px 10px 10px 20px;margin-bottom: 20px;margin-top: 20px;text-size-adjust: 100%;line-height: 1.75em;border-radius: 5px;box-sizing: inherit;border-width: 1px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-color: rgb(255, 191, 82);background: rgb(255, 248, 230);\"><p><span style=\"color: #f48a00;font-size: 32px;line-height: 0.6;margin-left: -15px;\">\u275d<\/span><\/p>\n<p style=\"padding-top: 8px;padding-bottom: 8px;letter-spacing: 0.1em;font-size: 16px;word-spacing: 0.1em;text-align: justify;line-height: 26px;margin-top: -15px;color: rgba(0, 0, 0, 0.85);\">\u4eca\u5929\u7684\u5206\u4eab\u5c31\u5230\u8fd9\u91cc\uff0c\u611f\u8c22\u4f60\u7684\u89c2\u770b\uff0c\u4e0b\u671f\u89c1\u3002<\/p>\n<\/blockquote>\n<\/section>\n<p style=\"display: none;\"><mp-style-type data-value=\"3\"><\/mp-style-type><\/p>\n<blockquote>\n<p>\u672c\u7bc7\u6587\u7ae0\u6765\u6e90\u4e8e\u5fae\u4fe1\u516c\u4f17\u53f7:                 \u5218\u724c              <\/p>\n<\/blockquote>\n<\/div>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd \u4eca\u5929\u8981\u5206\u4eab\u7684\u662fSpring\u7684@DependsOn\u6ce8\u89e3\uff0c\u5bf9\u4e8e@DependsOn\uff0c\u6211\u4eec\u4ece\u5b83\u7684\u540d\u79f0\u91cc\u9762\u5c31\u80fd\u770b\u51fa\u610f\u601d\u662f\u201c\u4f9d\u8d56\u4e8e\u201d\uff0c &#8230;<\/p>\n","protected":false},"author":2,"featured_media":713,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-715","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552-150x150.jpeg","content_first_image":null,"post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552-300x128.jpeg","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552.jpeg","post_frist_image":null,"post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552-300x128.jpeg","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552.jpeg","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230528015556552.jpeg","post_all_images":[],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2023-05-27","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":372,"next_post_id":1005,"next_post_title":"\u6570\u636e\u5e93\u94fe\u63a5\u6c60\u7ec8\u4e8e\u641e\u5bf9\u4e86\uff0c\u8fd9\u6b21\u76f4\u63a5\u4ece100ms\u4f18\u5316\u52303ms\uff01","previous_post_id":917,"previous_post_title":"Spring-15 Spring Certified Professional \u8bd5\u9898\u6574\u7406 \u2460","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=715"}],"version-history":[{"count":0,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media\/713"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}