{"id":64584,"date":"2026-01-23T19:40:21","date_gmt":"2026-01-23T11:40:21","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/64584.html"},"modified":"2026-01-23T19:40:21","modified_gmt":"2026-01-23T11:40:21","slug":"spring%e5%ae%b9%e5%99%a8%e5%90%af%e5%8a%a8%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/64584.html","title":{"rendered":"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b"},"content":{"rendered":"<h2><\/h2>\n<p>\u672c\u6587\u57fa\u4e8eSpring Framework\u6e90\u7801&#xff0c;\u4ee5\u300cAnnotationConfigApplicationContext\u300d\u4e3a\u5165\u53e3&#xff08;Java Config\u65b9\u5f0f&#xff09;&#xff0c;\u5168\u9762\u62c6\u89e3Spring\u5bb9\u5668\u542f\u52a8\u7684\u5b8c\u6574\u6d41\u7a0b&#xff0c;\u5305\u542b\u521d\u59cb\u5316\u3001\u914d\u7f6e\u7c7b\u6ce8\u518c\u3001\u5bb9\u5668\u5237\u65b0\u4e09\u5927\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u7ed3\u5408\u6e90\u7801\u9010\u53e5\u5206\u6790\u5173\u952e\u903b\u8f91&#xff0c;\u8865\u5145\u6838\u5fc3\u6982\u5ff5\u3001\u6269\u5c55\u77e5\u8bc6\u70b9\u53ca\u5b9e\u6218\u5173\u8054&#xff0c;\u52a9\u529b\u6df1\u5165\u7406\u89e3Spring\u5e95\u5c42\u539f\u7406\u3002<\/p>\n<p>\u6838\u5fc3\u524d\u63d0&#xff1a;<\/p>\n<p>Spring\u5bb9\u5668\u542f\u52a8\u7684\u672c\u8d28\u662f\u300c\u521b\u5efaBeanFactory\u3001\u6ce8\u518cBeanDefinition\u3001\u521d\u59cb\u5316Bean\u3001\u5efa\u7acb\u4f9d\u8d56\u5173\u7cfb\u300d\u7684\u8fc7\u7a0b\u3002\u65e0\u8bba\u662fJava Config&#xff08;AnnotationConfigApplicationContext&#xff09;\u8fd8\u662fXML\u914d\u7f6e&#xff08;ClassPathXmlApplicationContext&#xff09;&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u4e00\u81f4&#xff0c;\u5747\u7ee7\u627f\u81eaAbstractApplicationContext&#xff0c;\u6838\u5fc3\u65b9\u6cd5refresh()\u5b9a\u4e49\u4e8e\u6b64\u7c7b\u4e2d\u3002<\/p>\n<h2>\u4e00\u3001Spring\u542f\u52a8\u6838\u5fc3\u4e09\u6b65\u9aa4\u603b\u89c8<\/h2>\n<p>Spring\u5bb9\u5668\u542f\u52a8\u6574\u4f53\u53ef\u5f52\u7eb3\u4e3a\u4e09\u5927\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u5bf9\u5e94AnnotationConfigApplicationContext\u7684\u6784\u9020\u65b9\u6cd5\u6e90\u7801&#xff0c;\u903b\u8f91\u6e05\u6670\u4e14\u5c42\u5c42\u9012\u8fdb&#xff1a;<\/p>\n<p>\/\/ AnnotationConfigApplicationContext\u6784\u9020\u65b9\u6cd5&#xff08;Java Config\u5165\u53e3&#xff09;<br \/>\npublic AnnotationConfigApplicationContext(Class&lt;?&gt;&#8230; annotatedClasses) {<br \/>\n    \/\/ \u6b65\u9aa41&#xff1a;\u521d\u59cb\u5316Spring\u5bb9\u5668&#xff0c;\u6ce8\u518c\u5185\u7f6eBeanPostProcessor\u7684BeanDefinition<br \/>\n    this();<br \/>\n    \/\/ \u6b65\u9aa42&#xff1a;\u5c06\u7528\u6237\u914d\u7f6e\u7c7b&#xff08;\u5982SpringConfig&#xff09;\u7684BeanDefinition\u6ce8\u518c\u5230\u5bb9\u5668<br \/>\n    register(annotatedClasses);<br \/>\n    \/\/ \u6b65\u9aa43&#xff1a;\u8c03\u7528refresh()\u5237\u65b0\u5bb9\u5668&#xff0c;\u5b8c\u6210Bean\u521d\u59cb\u5316\u3001\u4f9d\u8d56\u6ce8\u5165\u7b49\u6838\u5fc3\u64cd\u4f5c<br \/>\n    refresh();<br \/>\n} <\/p>\n<h2>\u4e8c\u3001\u6b65\u9aa41&#xff1a;\u5bb9\u5668\u521d\u59cb\u5316\u6d41\u7a0b&#xff08;this()\u65e0\u53c2\u6784\u9020&#xff09;<\/h2>\n<p>\u8c03\u7528\u65e0\u53c2\u6784\u9020\u65b9\u6cd5this()&#xff0c;\u6838\u5fc3\u76ee\u7684\u662f\u300c\u521d\u59cb\u5316\u5bb9\u5668\u57fa\u7840\u7ec4\u4ef6&#xff0c;\u4e3a\u540e\u7eedBeanDefinition\u6ce8\u518c\u548c\u89e3\u6790\u505a\u51c6\u5907\u300d&#xff0c;\u5177\u4f53\u5b8c\u62103\u4ef6\u6838\u5fc3\u4e8b&#xff0c;\u540c\u65f6\u6ce8\u518cSpring\u5185\u7f6e\u7684\u540e\u7f6e\u5904\u7406\u5668BeanDefinition\u3002<\/p>\n<h3>1.1 \u6838\u5fc3\u64cd\u4f5c\u62c6\u89e3<\/h3>\n<li>\n<p>\u5b9e\u4f8b\u5316BeanFactory\u5de5\u5382&#xff1a;\u521b\u5efaDefaultListableBeanFactory\u5b9e\u4f8b&#xff0c;\u8fd9\u662fSpring\u6838\u5fc3\u7684Bean\u5de5\u5382&#xff0c;\u8d1f\u8d23Bean\u7684\u521b\u5efa\u3001\u5b58\u50a8\u3001\u7ba1\u7406&#xff0c;\u540e\u7eed\u6240\u6709BeanDefinition\u90fd\u4f1a\u6ce8\u518c\u5230\u8be5\u5de5\u5382\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u4f8b\u5316BeanDefinitionReader\u6ce8\u89e3\u89e3\u6790\u5668&#xff1a;\u7528\u4e8e\u89e3\u6790\u5e26\u6709\u7279\u5b9a\u6ce8\u89e3&#xff08;&#064;Component\u3001&#064;Service\u3001&#064;Repository\u3001&#064;Controller\u3001&#064;Configuration\u7b49&#xff09;\u7684\u7c7b&#xff0c;\u5c06\u5176\u8f6c\u5316\u4e3aBeanDefinition\u5bf9\u8c61\u3002 \u8865\u5145&#xff1a;BeanDefinition\u662fSpring\u6838\u5fc3\u6570\u636e\u7ed3\u6784&#xff0c;\u5b58\u50a8Bean\u7684\u6240\u6709\u5143\u4fe1\u606f&#xff08;\u7c7b\u540d\u3001\u662f\u5426\u5355\u4f8b\u3001\u662f\u5426\u61d2\u52a0\u8f7d\u3001\u4f9d\u8d56\u5173\u7cfb\u3001\u521d\u59cb\u5316\u65b9\u6cd5\u3001\u9500\u6bc1\u65b9\u6cd5\u7b49&#xff09;&#xff0c;\u662fBean\u521b\u5efa\u7684\u201c\u84dd\u56fe\u201d\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b9e\u4f8b\u5316ClassPathBeanDefinitionScanner\u8def\u5f84\u626b\u63cf\u5668&#xff1a;\u7528\u4e8e\u626b\u63cf\u6307\u5b9a\u5305\u8def\u5f84\u4e0b\u7684\u6240\u6709\u7c7b&#xff0c;\u7b5b\u9009\u51fa\u5e26\u6709\u6ce8\u89e3\u7684\u7c7b&#xff0c;\u4ea4\u7ed9BeanDefinitionReader\u89e3\u6790\u4e3aBeanDefinition\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u5185\u7f6e\u540e\u7f6e\u5904\u7406\u5668BeanDefinition&#xff1a;\u901a\u8fc7AnnotationConfigUtils.registerAnnotationConfigProcessors()\u65b9\u6cd5&#xff0c;\u5411\u5bb9\u5668\u6ce8\u518cSpring\u5185\u7f6e\u7684BeanDefinitionRegistryPostProcessor\u548cBeanPostProcessor&#xff0c;\u6838\u5fc3\u5305\u62ec&#xff1a;<\/p>\n<li>\n<p>ConfigurationClassPostProcessor&#xff1a;BeanFactory\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u6838\u5fc3\u804c\u8d23\u662f\u626b\u63cf\u914d\u7f6e\u7c7b\u3001\u89e3\u6790&#064;ComponentScan\u3001&#064;Import\u3001&#064;Bean\u7b49\u6ce8\u89e3&#xff0c;\u5b8c\u6210BeanDefinition\u7684\u6279\u91cf\u6ce8\u518c\u3002<\/p>\n<\/li>\n<li>\n<p>AutowiredAnnotationBeanPostProcessor&#xff1a;Bean\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u6838\u5fc3\u804c\u8d23\u662f\u5904\u7406&#064;Autowired\u3001&#064;Value\u6ce8\u89e3\u7684\u81ea\u52a8\u6ce8\u5165\u3002<\/p>\n<\/li>\n<li>\n<p>CommonAnnotationBeanPostProcessor&#xff1a;Bean\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5904\u7406&#064;Resource\u3001&#064;PostConstruct\u3001&#064;PreDestroy\u7b49\u6ce8\u89e3\u3002<\/p>\n<\/li>\n<\/li>\n<h3>1.2 \u6838\u5fc3\u6e90\u7801\u5256\u6790&#xff08;AnnotationConfigApplicationContext\u65e0\u53c2\u6784\u9020&#xff09;<\/h3>\n<p>public AnnotationConfigApplicationContext() {<br \/>\n    \/\/ 1. \u5b9e\u4f8b\u5316BeanDefinitionReader&#xff0c;\u5173\u8054\u5f53\u524d\u5bb9\u5668&#xff08;\u7528\u4e8e\u89e3\u6790\u6ce8\u89e3\u7c7b\u4e3aBeanDefinition&#xff09;<br \/>\n    this.reader &#061; new AnnotatedBeanDefinitionReader(this);<br \/>\n    \/\/ 2. \u5b9e\u4f8b\u5316ClassPathBeanDefinitionScanner&#xff0c;\u5173\u8054\u5f53\u524d\u5bb9\u5668&#xff08;\u7528\u4e8e\u626b\u63cf\u5305\u8def\u5f84&#xff09;<br \/>\n    this.scanner &#061; new ClassPathBeanDefinitionScanner(this);<br \/>\n}<\/p>\n<p>\/\/ AnnotatedBeanDefinitionReader\u6784\u9020\u65b9\u6cd5\u4e2d&#xff0c;\u4f1a\u8c03\u7528AnnotationConfigUtils\u6ce8\u518c\u5185\u7f6e\u7ec4\u4ef6<br \/>\npublic AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry) {<br \/>\n    this(registry, getOrCreateEnvironment(registry));<br \/>\n}<\/p>\n<p>public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment) {<br \/>\n    this.registry &#061; registry;<br \/>\n    this.conditionEvaluator &#061; new ConditionEvaluator(registry, environment, null);<br \/>\n    \/\/ \u6838\u5fc3&#xff1a;\u6ce8\u518cSpring\u5185\u7f6e\u7684\u540e\u7f6e\u5904\u7406\u5668BeanDefinition<br \/>\n    AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);<br \/>\n}<\/p>\n<h3>1.3 \u6269\u5c55\u77e5\u8bc6\u70b9<\/h3>\n<ul>\n<li>\n<p>BeanFactory\u4e0eApplicationContext\u7684\u533a\u522b&#xff1a;BeanFactory\u662fSpring\u6700\u57fa\u7840\u7684Bean\u5bb9\u5668&#xff0c;\u4ec5\u63d0\u4f9bBean\u7684\u521b\u5efa\u548c\u7ba1\u7406\u529f\u80fd&#xff1b;ApplicationContext\u662fBeanFactory\u7684\u5b50\u7c7b&#xff0c;\u9664\u4e86BeanFactory\u7684\u529f\u80fd&#xff0c;\u8fd8\u96c6\u6210\u4e86\u56fd\u9645\u5316\u3001\u4e8b\u4ef6\u53d1\u5e03\u3001\u8d44\u6e90\u52a0\u8f7d\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>\u5185\u7f6e\u540e\u7f6e\u5904\u7406\u5668\u7684\u4f5c\u7528&#xff1a;Spring\u5185\u7f6e\u540e\u7f6e\u5904\u7406\u5668\u662f\u5bb9\u5668\u6b63\u5e38\u5de5\u4f5c\u7684\u57fa\u7840&#xff0c;\u65e0\u9700\u7528\u6237\u624b\u52a8\u914d\u7f6e&#xff0c;\u4f1a\u81ea\u52a8\u6ce8\u518c\u5e76\u751f\u6548&#xff0c;\u8d1f\u8d23\u5b8c\u6210\u6ce8\u89e3\u89e3\u6790\u3001\u81ea\u52a8\u6ce8\u5165\u3001Bean\u751f\u547d\u5468\u671f\u5e72\u9884\u7b49\u6838\u5fc3\u64cd\u4f5c\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u4e09\u3001\u6b65\u9aa42&#xff1a;\u6ce8\u518c\u914d\u7f6e\u7c7b\u5230\u5bb9\u5668&#xff08;register()\u65b9\u6cd5&#xff09;<\/h2>\n<p>register(annotatedClasses)\u65b9\u6cd5\u7684\u6838\u5fc3\u662f\u300c\u5c06\u7528\u6237\u4f20\u5165\u7684\u914d\u7f6e\u7c7b&#xff08;\u5982\u6807\u6ce8&#064;Configuration\u7684\u7c7b&#xff09;\u89e3\u6790\u4e3aBeanDefinition&#xff0c;\u5e76\u6ce8\u518c\u5230BeanFactory\u4e2d\u300d&#xff0c;\u4e3a\u540e\u7eedrefresh()\u9636\u6bb5\u7684Bean\u626b\u63cf\u548c\u521d\u59cb\u5316\u505a\u51c6\u5907\u3002<\/p>\n<h3>2.1 \u6838\u5fc3\u64cd\u4f5c\u62c6\u89e3<\/h3>\n<li>\n<p>\u89e3\u6790\u914d\u7f6e\u7c7b\u4e3aBeanDefinition&#xff1a;\u901a\u8fc7AnnotatedGenericBeanDefinition\u5c01\u88c5\u914d\u7f6e\u7c7b&#xff0c;\u5c06\u914d\u7f6e\u7c7b\u7684\u5143\u4fe1\u606f&#xff08;\u6ce8\u89e3\u3001\u7c7b\u540d\u3001\u4f5c\u7528\u57df\u7b49&#xff09;\u5b58\u50a8\u5230BeanDefinition\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u6761\u4ef6\u7b5b\u9009&#xff08;&#064;Conditional\u6ce8\u89e3\u5904\u7406&#xff09;&#xff1a;\u901a\u8fc7ConditionEvaluator\u5224\u65ad\u914d\u7f6e\u7c7b\u662f\u5426\u6ee1\u8db3&#064;Conditional\u6ce8\u89e3\u7684\u6761\u4ef6&#xff0c;\u4e0d\u6ee1\u8db3\u5219\u8df3\u8fc7\u6ce8\u518c\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u4f5c\u7528\u57df\u548cBean\u540d\u79f0&#xff1a;\u89e3\u6790&#064;Scope\u6ce8\u89e3\u786e\u5b9aBean\u7684\u4f5c\u7528\u57df&#xff08;\u9ed8\u8ba4\u5355\u4f8b&#xff09;&#xff0c;\u901a\u8fc7BeanNameGenerator\u751f\u6210Bean\u7684\u540d\u79f0&#xff08;\u9ed8\u8ba4\u9996\u5b57\u6bcd\u5c0f\u5199\u7684\u7c7b\u540d&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5904\u7406\u901a\u7528\u6ce8\u89e3&#xff1a;\u901a\u8fc7AnnotationConfigUtils.processCommonDefinitionAnnotations()\u5904\u7406&#064;Primary\u3001&#064;Lazy\u3001&#064;DependsOn\u7b49\u901a\u7528\u6ce8\u89e3&#xff0c;\u8bbe\u7f6e\u5230BeanDefinition\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u5230\u5bb9\u5668&#xff1a;\u5c06\u5c01\u88c5\u597d\u7684BeanDefinitionHolder\u6ce8\u518c\u5230BeanFactory\u7684BeanDefinitionRegistry\u4e2d&#xff0c;\u5b8c\u6210\u914d\u7f6e\u7c7b\u7684\u6ce8\u518c\u3002<\/p>\n<\/li>\n<h3>2.2 \u6838\u5fc3\u6e90\u7801\u5256\u6790&#xff08;AnnotatedBeanDefinitionReader#doRegisterBean&#xff09;<\/h3>\n<p>\/\/ \u6838\u5fc3\u65b9\u6cd5&#xff1a;\u6ce8\u518c\u5355\u4e2a\u6ce8\u89e3\u7c7b&#xff08;\u914d\u7f6e\u7c7b\u6216\u666e\u901aBean&#xff09;<br \/>\n&lt;T&gt; void doRegisterBean(Class&lt;T&gt; annotatedClass, &#064;Nullable Supplier&lt;T&gt; instanceSupplier, &#064;Nullable String name,<br \/>\n&#064;Nullable Class&lt;? extends Annotation&gt;[] qualifiers, BeanDefinitionCustomizer&#8230; definitionCustomizers) {<br \/>\n\/\/ 1. \u89e3\u6790\u914d\u7f6e\u7c7b\u4e3aAnnotatedGenericBeanDefinition&#xff08;\u5305\u542b\u7c7b\u7684\u6ce8\u89e3\u5143\u4fe1\u606f&#xff09;<br \/>\nAnnotatedGenericBeanDefinition abd &#061; new AnnotatedGenericBeanDefinition(annotatedClass);<br \/>\n\/\/ 2. \u5904\u7406&#064;Conditional\u6ce8\u89e3&#xff0c;\u5224\u65ad\u662f\u5426\u8df3\u8fc7\u6ce8\u518c<br \/>\nif (this.conditionEvaluator.shouldSkip(abd.getMetadata())) {<br \/>\nreturn;<br \/>\n}<\/p>\n<p>\/\/ 3. \u8bbe\u7f6e\u5b9e\u4f8b\u63d0\u4f9b\u5668&#xff08;\u53ef\u9009&#xff0c;\u7528\u4e8e\u81ea\u5b9a\u4e49Bean\u5b9e\u4f8b\u521b\u5efa&#xff09;<br \/>\nabd.setInstanceSupplier(instanceSupplier);<br \/>\n\/\/ 4. \u89e3\u6790&#064;Scope\u6ce8\u89e3&#xff0c;\u786e\u5b9aBean\u4f5c\u7528\u57df&#xff08;\u9ed8\u8ba4singleton&#xff09;<br \/>\nScopeMetadata scopeMetadata &#061; this.scopeMetadataResolver.resolveScopeMetadata(abd);<br \/>\nabd.setScope(scopeMetadata.getScopeName());<br \/>\n\/\/ 5. \u751f\u6210Bean\u540d\u79f0&#xff08;\u9ed8\u8ba4\u7c7b\u540d\u9996\u5b57\u6bcd\u5c0f\u5199&#xff0c;\u53ef\u901a\u8fc7&#064;Bean\u6307\u5b9a&#xff09;<br \/>\nString beanName &#061; (name !&#061; null ? name : this.beanNameGenerator.generateBeanName(abd, this.registry));<br \/>\n\/\/ 6. \u5904\u7406\u901a\u7528\u6ce8\u89e3&#xff1a;&#064;Primary\u3001&#064;Lazy\u3001&#064;DependsOn\u7b49<br \/>\nAnnotationConfigUtils.processCommonDefinitionAnnotations(abd);<br \/>\n\/\/ 7. \u5904\u7406\u81ea\u5b9a\u4e49\u9650\u5b9a\u7b26\u6ce8\u89e3&#xff08;\u5982&#064;Qualifier&#xff09;<br \/>\nif (qualifiers !&#061; null) {<br \/>\nfor (Class&lt;? extends Annotation&gt; qualifier : qualifiers) {<br \/>\nif (Primary.class &#061;&#061; qualifier) {<br \/>\nabd.setPrimary(true); \/\/ \u6807\u8bb0\u4e3a\u9996\u9009Bean<br \/>\n}<br \/>\nelse if (Lazy.class &#061;&#061; qualifier) {<br \/>\nabd.setLazyInit(true); \/\/ \u6807\u8bb0\u4e3a\u61d2\u52a0\u8f7d<br \/>\n}<br \/>\nelse {<br \/>\nabd.addQualifier(new AutowireCandidateQualifier(qualifier));<br \/>\n}<br \/>\n}<br \/>\n}<br \/>\n\/\/ 8. \u5e94\u7528\u81ea\u5b9a\u4e49BeanDefinition\u914d\u7f6e&#xff08;\u7528\u6237\u6269\u5c55&#xff09;<br \/>\nfor (BeanDefinitionCustomizer customizer : definitionCustomizers) {<br \/>\ncustomizer.customize(abd);<br \/>\n}<br \/>\n\/\/ 9. \u5c01\u88c5\u4e3aBeanDefinitionHolder&#xff08;\u5305\u542bBeanDefinition\u548cBean\u540d\u79f0&#xff09;<br \/>\nBeanDefinitionHolder definitionHolder &#061; new BeanDefinitionHolder(abd, beanName);<br \/>\n\/\/ 10. \u5904\u7406\u4f5c\u7528\u57df\u4ee3\u7406&#xff08;\u5982&#064;Scope(proxyMode &#061; ScopedProxyMode.INTERFACES)&#xff09;<br \/>\ndefinitionHolder &#061; AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);<br \/>\n\/\/ 11. \u6700\u7ec8\u6ce8\u518c\u5230BeanDefinitionRegistry&#xff08;BeanFactory\u7684\u6838\u5fc3\u7ec4\u4ef6&#xff09;<br \/>\nBeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, this.registry);<br \/>\n}<\/p>\n<h3>2.3 \u6269\u5c55\u77e5\u8bc6\u70b9<\/h3>\n<ul>\n<li>\n<p>\u914d\u7f6e\u7c7b\u7684\u7279\u6b8a\u5730\u4f4d&#xff1a;\u914d\u7f6e\u7c7b\u672c\u8eab\u4e5f\u662f\u4e00\u4e2aBean&#xff0c;\u4f46\u5176\u6838\u5fc3\u4f5c\u7528\u662f\u4f5c\u4e3a\u201c\u5165\u53e3\u201d&#xff0c;\u540e\u7eed\u901a\u8fc7ConfigurationClassPostProcessor\u89e3\u6790\u914d\u7f6e\u7c7b\u4e2d\u7684&#064;ComponentScan\u3001&#064;Import\u3001&#064;Bean\u7b49\u6ce8\u89e3&#xff0c;\u6279\u91cf\u6ce8\u518c\u5176\u4ed6Bean\u3002<\/p>\n<\/li>\n<li>\n<p>&#064;Scope\u6ce8\u89e3\u7684proxyMode\u5c5e\u6027&#xff1a;\u7528\u4e8e\u8bbe\u7f6e\u4f5c\u7528\u57df\u4ee3\u7406\u6a21\u5f0f&#xff0c;\u5982REQUEST\u3001SESSION\u4f5c\u7528\u57df\u7684Bean&#xff0c;\u9700\u8981\u901a\u8fc7\u4ee3\u7406\u6a21\u5f0f\u6ce8\u5165\u5230\u5355\u4f8bBean\u4e2d&#xff0c;\u5426\u5219\u4f1a\u51fa\u73b0\u751f\u547d\u5468\u671f\u4e0d\u5339\u914d\u95ee\u9898\u3002<\/p>\n<\/li>\n<li>\n<p>BeanNameGenerator\u7684\u4f5c\u7528&#xff1a;\u9ed8\u8ba4\u4f7f\u7528AnnotationBeanNameGenerator&#xff0c;\u751f\u6210\u89c4\u5219\u4e3a\u201c\u7c7b\u540d\u9996\u5b57\u6bcd\u5c0f\u5199\u201d&#xff0c;\u53ef\u901a\u8fc7\u81ea\u5b9a\u4e49BeanNameGenerator\u4fee\u6539Bean\u540d\u79f0\u751f\u6210\u89c4\u5219\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u56db\u3001\u6b65\u9aa43&#xff1a;\u5bb9\u5668\u5237\u65b0\u6d41\u7a0b&#xff08;refresh()\u65b9\u6cd5&#xff09;<\/h2>\n<p>refresh()\u662fSpring\u5bb9\u5668\u542f\u52a8\u7684\u6838\u5fc3\u65b9\u6cd5&#xff0c;\u5b9a\u4e49\u4e8eAbstractApplicationContext\u4e2d&#xff0c;\u8d2f\u7a7f\u5bb9\u5668\u542f\u52a8\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f&#xff0c;\u5171\u62c6\u89e3\u4e3a12\u4e2a\u6b65\u9aa4&#xff0c;\u5b8c\u6210BeanFactory\u9884\u5904\u7406\u3001\u540e\u7f6e\u5904\u7406\u5668\u6267\u884c\u3001Bean\u521d\u59cb\u5316\u3001\u7ec4\u4ef6\u521d\u59cb\u5316\u7b49\u6240\u6709\u6838\u5fc3\u64cd\u4f5c\u3002<\/p>\n<p>\u6838\u5fc3\u7279\u5f81&#xff1a;refresh()\u65b9\u6cd5\u662f\u540c\u6b65\u65b9\u6cd5&#xff08;synchronized\u9501&#xff09;&#xff0c;\u786e\u4fdd\u5bb9\u5668\u5237\u65b0\u8fc7\u7a0b\u7ebf\u7a0b\u5b89\u5168&#xff1b;\u65e0\u8bba\u4f55\u79cd\u7c7b\u578b\u7684Spring\u5bb9\u5668&#xff08;\u7236\u5b50\u5bb9\u5668\u3001Feign\u9694\u79bb\u5bb9\u5668&#xff09;&#xff0c;\u90fd\u4f1a\u8c03\u7528\u6b64\u65b9\u6cd5\u5b8c\u6210\u521d\u59cb\u5316\u3002<\/p>\n<h3>3.1 refresh()\u65b9\u6cd5\u6574\u4f53\u6e90\u7801<\/h3>\n<p>public void refresh() throws BeansException, IllegalStateException {<br \/>\nsynchronized (this.startupShutdownMonitor) {<br \/>\n\/\/ 1. \u5237\u65b0\u524d\u7684\u9884\u5904\u7406<br \/>\nprepareRefresh();<\/p>\n<p>\/\/ 2. \u83b7\u53d6BeanFactory&#xff08;DefaultListableBeanFactory&#xff09;<br \/>\nConfigurableListableBeanFactory beanFactory &#061; obtainFreshBeanFactory();<\/p>\n<p>\/\/ 3. \u9884\u5904\u7406BeanFactory&#xff0c;\u6dfb\u52a0\u6838\u5fc3\u7ec4\u4ef6<br \/>\nprepareBeanFactory(beanFactory);<\/p>\n<p>try {<br \/>\n\/\/ 4. \u5b50\u7c7b\u6269\u5c55&#xff1a;BeanFactory\u9884\u5904\u7406\u540e\u8fdb\u4e00\u6b65\u8bbe\u7f6e<br \/>\npostProcessBeanFactory(beanFactory);<\/p>\n<p>\/\/ 5. \u6267\u884cBeanFactory\u540e\u7f6e\u5904\u7406\u5668&#xff08;\u89e3\u6790\u914d\u7f6e\u7c7b\u3001\u6279\u91cf\u6ce8\u518cBeanDefinition&#xff09;<br \/>\ninvokeBeanFactoryPostProcessors(beanFactory);<\/p>\n<p>\/\/ 6. \u6ce8\u518cBean\u540e\u7f6e\u5904\u7406\u5668&#xff08;\u5e72\u9884Bean\u521b\u5efa\u6d41\u7a0b&#xff09;<br \/>\nregisterBeanPostProcessors(beanFactory);<\/p>\n<p>\/\/ 7. \u521d\u59cb\u5316\u56fd\u9645\u5316\u7ec4\u4ef6&#xff08;MessageSource&#xff09;<br \/>\ninitMessageSource();<\/p>\n<p>\/\/ 8. \u521d\u59cb\u5316\u4e8b\u4ef6\u6d3e\u53d1\u5668&#xff08;ApplicationEventMulticaster&#xff09;<br \/>\ninitApplicationEventMulticaster();<\/p>\n<p>\/\/ 9. \u5b50\u7c7b\u6269\u5c55&#xff1a;\u5bb9\u5668\u5237\u65b0\u65f6\u81ea\u5b9a\u4e49\u903b\u8f91&#xff08;Web\u573a\u666f\u5e38\u7528&#xff09;<br \/>\nonRefresh();<\/p>\n<p>\/\/ 10. \u6ce8\u518c\u76d1\u542c\u5668&#xff0c;\u6d3e\u53d1\u65e9\u671f\u4e8b\u4ef6<br \/>\nregisterListeners();<\/p>\n<p>\/\/ 11. \u521d\u59cb\u5316\u6240\u6709\u975e\u61d2\u52a0\u8f7d\u5355\u4f8bBean&#xff08;\u6838\u5fc3\u6b65\u9aa4&#xff09;<br \/>\nfinishBeanFactoryInitialization(beanFactory);<\/p>\n<p>\/\/ 12. \u5bb9\u5668\u5237\u65b0\u5b8c\u6210&#xff0c;\u53d1\u5e03\u4e8b\u4ef6<br \/>\nfinishRefresh();<br \/>\n}<\/p>\n<p>catch (BeansException ex) {<br \/>\nif (logger.isWarnEnabled()) {<br \/>\nlogger.warn(&#034;Exception encountered during context initialization &#8211; &#034; &#043;<br \/>\n&#034;cancelling refresh attempt: &#034; &#043; ex);<br \/>\n}<\/p>\n<p>\/\/ \u9500\u6bc1\u5df2\u521b\u5efa\u7684Bean&#xff0c;\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f<br \/>\ndestroyBeans();<\/p>\n<p>\/\/ \u91cd\u7f6e\u5bb9\u5668\u6fc0\u6d3b\u72b6\u6001<br \/>\ncancelRefresh(ex);<\/p>\n<p>\/\/ \u629b\u51fa\u5f02\u5e38&#xff0c;\u544a\u77e5\u542f\u52a8\u5931\u8d25<br \/>\nthrow ex;<br \/>\n}<\/p>\n<p>finally {<br \/>\n\/\/ \u6e05\u9664Spring\u5185\u6838\u4e2d\u7684\u4e34\u65f6\u7f13\u5b58&#xff08;\u5982\u7c7b\u52a0\u8f7d\u5668\u7f13\u5b58&#xff09;<br \/>\nresetCommonCaches();<br \/>\n}<br \/>\n}<br \/>\n}<\/p>\n<h3>3.2 \u9010\u6b65\u9aa4\u8be6\u7ec6\u89e3\u6790<\/h3>\n<h4>\u6b65\u9aa41&#xff1a;prepareRefresh()\u2014\u2014\u5237\u65b0\u524d\u9884\u5904\u7406<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u521d\u59cb\u5316\u5bb9\u5668\u73af\u5883\u3001\u6821\u9a8c\u5c5e\u6027\u5408\u6cd5\u6027\u3001\u4fdd\u5b58\u65e9\u671f\u4e8b\u4ef6&#xff0c;\u4e3a\u540e\u7eed\u5237\u65b0\u64cd\u4f5c\u505a\u51c6\u5907\u3002<\/p>\n<li>\n<p>initPropertySources()&#xff1a;\u521d\u59cb\u5316\u5c5e\u6027\u6e90&#xff0c;\u5b50\u7c7b\u53ef\u91cd\u5199\u6b64\u65b9\u6cd5\u81ea\u5b9a\u4e49\u5c5e\u6027\u8bbe\u7f6e&#xff08;\u5982\u6dfb\u52a0\u81ea\u5b9a\u4e49\u914d\u7f6e\u6587\u4ef6&#xff09;\u3002\u9ed8\u8ba4\u5b9e\u73b0\u4e3a\u7a7a&#xff0c;\u7559\u7ed9\u7528\u6237\u6269\u5c55\u3002<\/p>\n<\/li>\n<li>\n<p>validateRequiredProperties()&#xff1a;\u6821\u9a8c\u5bb9\u5668\u73af\u5883\u4e2d\u7684\u5fc5\u586b\u5c5e\u6027&#xff08;\u901a\u8fc7&#064;Required\u6ce8\u89e3\u6216\u914d\u7f6e\u6587\u4ef6\u6307\u5b9a&#xff09;&#xff0c;\u82e5\u7f3a\u5931\u5219\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u65e9\u671f\u4e8b\u4ef6\u96c6\u5408&#xff1a;\u521b\u5efaLinkedHashSet&lt;ApplicationEvent&gt;\u5b58\u50a8\u65e9\u671f\u4e8b\u4ef6&#xff08;\u5728\u4e8b\u4ef6\u6d3e\u53d1\u5668\u521d\u59cb\u5316\u524d\u4ea7\u751f\u7684\u4e8b\u4ef6&#xff09;&#xff0c;\u540e\u7eed\u4f1a\u7edf\u4e00\u6d3e\u53d1\u3002<\/p>\n<\/li>\n<p>protected void prepareRefresh() {<br \/>\n\/\/ \u8bb0\u5f55\u5bb9\u5668\u542f\u52a8\u65f6\u95f4<br \/>\nthis.startupDate &#061; System.currentTimeMillis();<br \/>\n\/\/ \u6807\u8bb0\u5bb9\u5668\u4e3a\u6fc0\u6d3b\u72b6\u6001<br \/>\nthis.closed.set(false);<br \/>\nthis.active.set(true);<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u5c5e\u6027\u6e90&#xff08;\u5b50\u7c7b\u6269\u5c55&#xff09;<br \/>\ninitPropertySources();<\/p>\n<p>\/\/ \u6821\u9a8c\u5fc5\u586b\u5c5e\u6027<br \/>\ngetEnvironment().validateRequiredProperties();<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u65e9\u671f\u4e8b\u4ef6\u96c6\u5408<br \/>\nif (this.earlyApplicationEvents &#061;&#061; null) {<br \/>\nthis.earlyApplicationEvents &#061; new LinkedHashSet&lt;&gt;();<br \/>\n}<br \/>\n} <\/p>\n<h4>\u6b65\u9aa42&#xff1a;obtainFreshBeanFactory()\u2014\u2014\u83b7\u53d6BeanFactory<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u83b7\u53d6\u6b65\u9aa41\u4e2d\u521d\u59cb\u5316\u7684DefaultListableBeanFactory&#xff0c;\u786e\u4fddBeanFactory\u5904\u4e8e\u53ef\u7528\u72b6\u6001\u3002<\/p>\n<li>\n<p>refreshBeanFactory()&#xff1a;\u5237\u65b0BeanFactory&#xff0c;\u8bbe\u7f6e\u5e8f\u5217\u5316ID&#xff08;\u786e\u4fdd\u5bb9\u5668\u53ef\u5e8f\u5217\u5316&#xff09;&#xff0c;GenericApplicationContext\u7684\u5b9e\u73b0\u4e3a\u91cd\u7f6eBeanFactory\u5e76\u91cd\u65b0\u5173\u8054\u3002<\/p>\n<\/li>\n<li>\n<p>getBeanFactory()&#xff1a;\u8fd4\u56de\u5bb9\u5668\u4e2d\u7684BeanFactory\u5b9e\u4f8b&#xff08;DefaultListableBeanFactory&#xff09;&#xff0c;\u540e\u7eed\u6240\u6709\u64cd\u4f5c\u5747\u57fa\u4e8e\u6b64BeanFactory\u3002<\/p>\n<\/li>\n<p>\u6269\u5c55&#xff1a;\u6b64\u6b65\u9aa4\u786e\u4fddBeanFactory\u662f\u6700\u65b0\u72b6\u6001&#xff0c;\u907f\u514d\u56e0\u5bb9\u5668\u91cd\u590d\u5237\u65b0\u5bfc\u81f4\u7684BeanFactory\u4e0d\u4e00\u81f4\u95ee\u9898\u3002<\/p>\n<h4>\u6b65\u9aa43&#xff1a;prepareBeanFactory()\u2014\u2014BeanFactory\u9884\u5904\u7406<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u5411BeanFactory\u6dfb\u52a0\u6838\u5fc3\u7ec4\u4ef6\u3001\u8bbe\u7f6e\u57fa\u7840\u914d\u7f6e&#xff0c;\u786e\u4fddBeanFactory\u5177\u5907Bean\u521b\u5efa\u548c\u7ba1\u7406\u7684\u57fa\u7840\u80fd\u529b\u3002<\/p>\n<li>\n<p>\u57fa\u7840\u914d\u7f6e\u8bbe\u7f6e&#xff1a;\u8bbe\u7f6eBeanFactory\u7684\u7c7b\u52a0\u8f7d\u5668\u3001\u8868\u8fbe\u5f0f\u89e3\u6790\u5668&#xff08;\u5904\u7406SpEL\u8868\u8fbe\u5f0f&#xff09;\u3001\u7c7b\u578b\u8f6c\u6362\u5668\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6dfb\u52a0BeanPostProcessor&#xff1a;ApplicationContextAwareProcessor&#xff1a;\u7528\u4e8e\u5904\u7406Aware\u63a5\u53e3&#xff08;EnvironmentAware\u3001ResourceLoaderAware\u7b49&#xff09;&#xff0c;\u5c06\u5bb9\u5668\u7ec4\u4ef6\u6ce8\u5165\u5230Bean\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u8bbe\u7f6e\u5ffd\u7565\u81ea\u52a8\u88c5\u914d\u7684\u63a5\u53e3&#xff1a;EnvironmentAware\u3001EmbeddedValueResolverAware\u7b49\u63a5\u53e3&#xff0c;\u907f\u514d\u8fd9\u4e9b\u63a5\u53e3\u88ab&#064;Autowired\u81ea\u52a8\u6ce8\u5165&#xff0c;\u800c\u662f\u901a\u8fc7ApplicationContextAwareProcessor\u624b\u52a8\u6ce8\u5165\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u53ef\u81ea\u52a8\u88c5\u914d\u7684\u7ec4\u4ef6&#xff1a;\u5411BeanFactory\u6ce8\u518cBeanFactory\u3001ResourceLoader\u3001ApplicationEventPublisher\u3001ApplicationContext\u7b49\u7ec4\u4ef6&#xff0c;\u5141\u8bb8Bean\u901a\u8fc7&#064;Autowired\u81ea\u52a8\u6ce8\u5165\u8fd9\u4e9b\u5bb9\u5668\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u6dfb\u52a0BeanPostProcessor&#xff1a;ApplicationListenerDetector&#xff1a;\u68c0\u6d4bBean\u662f\u5426\u4e3aApplicationListener\u7c7b\u578b&#xff0c;\u82e5\u662f\u5219\u6ce8\u518c\u5230\u5bb9\u5668\u7684\u4e8b\u4ef6\u76d1\u542c\u5668\u96c6\u5408\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u652f\u6301AspectJ\u7f16\u8bd1\u65f6\u7ec7\u5165&#xff1a;\u82e5\u5b58\u5728AspectJ\u76f8\u5173\u7c7b&#xff0c;\u5411BeanFactory\u6dfb\u52a0AspectJWeavingEnabler&#xff0c;\u652f\u6301AOP\u5207\u9762\u7ec7\u5165\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u7cfb\u7edf\u7ec4\u4ef6&#xff1a;\u5411BeanFactory\u6ce8\u518cenvironment&#xff08;\u73af\u5883\u53d8\u91cf&#xff09;\u3001systemProperties&#xff08;\u7cfb\u7edf\u5c5e\u6027&#xff09;\u3001systemEnvironment&#xff08;\u7cfb\u7edf\u73af\u5883\u53d8\u91cf&#xff09;\u4e09\u4e2a\u7ec4\u4ef6&#xff0c;\u4f9bBean\u83b7\u53d6\u7cfb\u7edf\u4fe1\u606f\u3002<\/p>\n<\/li>\n<h4>\u6b65\u9aa44&#xff1a;postProcessBeanFactory()\u2014\u2014\u5b50\u7c7b\u6269\u5c55\u9884\u5904\u7406<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u7559\u7ed9\u5b50\u7c7b&#xff08;\u5982WebApplicationContext&#xff09;\u91cd\u5199&#xff0c;\u5728BeanFactory\u9884\u5904\u7406\u5b8c\u6210\u540e\u505a\u8fdb\u4e00\u6b65\u5b9a\u5236\u5316\u914d\u7f6e\u3002\u4f8b\u5982&#xff0c;Spring MVC\u7684AnnotationConfigWebApplicationContext\u4f1a\u91cd\u5199\u6b64\u65b9\u6cd5&#xff0c;\u6ce8\u518cSpring MVC\u76f8\u5173\u7684BeanPostProcessor\u3002<\/p>\n<p>\u6269\u5c55&#xff1a;\u666e\u901aJava Config\u573a\u666f\u4e0b&#xff0c;\u6b64\u65b9\u6cd5\u9ed8\u8ba4\u5b9e\u73b0\u4e3a\u7a7a&#xff0c;\u65e0\u9700\u989d\u5916\u5904\u7406\u3002<\/p>\n<h4>\u6b65\u9aa45&#xff1a;invokeBeanFactoryPostProcessors()\u2014\u2014\u6267\u884cBeanFactory\u540e\u7f6e\u5904\u7406\u5668<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u6267\u884cBeanFactoryPostProcessor\u63a5\u53e3\u7684\u65b9\u6cd5&#xff0c;\u5e72\u9884BeanFactory\u7684\u914d\u7f6e&#xff0c;\u6838\u5fc3\u662f\u5b8c\u6210\u300c\u914d\u7f6e\u7c7b\u89e3\u6790\u3001\u6279\u91cf\u6ce8\u518cBeanDefinition\u300d&#xff08;\u7531ConfigurationClassPostProcessor\u5b9e\u73b0&#xff09;\u3002<\/p>\n<p>BeanFactoryPostProcessor\u662fSpring\u7684\u6838\u5fc3\u6269\u5c55\u70b9&#xff0c;\u5206\u4e3a\u4e24\u7c7b&#xff1a;BeanDefinitionRegistryPostProcessor&#xff08;\u4f18\u5148\u6267\u884c&#xff0c;\u7528\u4e8e\u6ce8\u518cBeanDefinition&#xff09;\u548cBeanFactoryPostProcessor&#xff08;\u540e\u6267\u884c&#xff0c;\u7528\u4e8e\u4fee\u6539BeanDefinition&#xff09;\u3002<\/p>\n<li>\n<p>\u6267\u884cBeanDefinitionRegistryPostProcessor&#xff1a;<\/p>\n<li>\n<p>\u83b7\u53d6\u6240\u6709\u5b9e\u73b0BeanDefinitionRegistryPostProcessor\u63a5\u53e3\u7684Bean\u3002<\/p>\n<\/li>\n<li>\n<p>\u6309\u4f18\u5148\u7ea7\u6267\u884c&#xff1a;\u5148\u6267\u884c\u5b9e\u73b0PriorityOrdered\u63a5\u53e3\u7684&#xff0c;\u518d\u6267\u884c\u5b9e\u73b0Ordered\u63a5\u53e3\u7684&#xff0c;\u6700\u540e\u6267\u884c\u65e0\u4f18\u5148\u7ea7\u7684\u3002<\/p>\n<\/li>\n<li>\n<p>\u6838\u5fc3\u903b\u8f91&#xff1a;ConfigurationClassPostProcessor\u4f1a\u89e3\u6790\u914d\u7f6e\u7c7b\u4e2d\u7684&#064;ComponentScan\u6ce8\u89e3&#xff0c;\u626b\u63cf\u6307\u5b9a\u5305\u4e0b\u7684Bean\u5e76\u6ce8\u518cBeanDefinition&#xff1b;\u89e3\u6790&#064;Import\u3001&#064;Bean\u6ce8\u89e3&#xff0c;\u6ce8\u518c\u5bf9\u5e94BeanDefinition\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u6267\u884cBeanFactoryPostProcessor&#xff1a;<\/p>\n<li>\n<p>\u83b7\u53d6\u6240\u6709\u5b9e\u73b0BeanFactoryPostProcessor\u63a5\u53e3\u7684Bean\u3002<\/p>\n<\/li>\n<li>\n<p>\u6309\u4f18\u5148\u7ea7\u6267\u884c&#xff08;\u540c\u4e0a\u8ff0\u4f18\u5148\u7ea7\u89c4\u5219&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u6838\u5fc3\u903b\u8f91&#xff1a;\u4fee\u6539\u5df2\u6ce8\u518c\u7684BeanDefinition&#xff08;\u5982\u4fee\u6539Bean\u7684\u5c5e\u6027\u3001\u4f5c\u7528\u57df\u7b49&#xff09;\u3002<\/p>\n<\/li>\n<\/li>\n<p>\u6269\u5c55&#xff1a;\u6b64\u6b65\u9aa4\u662fBeanDefinition\u6ce8\u518c\u7684\u6838\u5fc3&#xff0c;\u5927\u90e8\u5206Bean&#xff08;\u5982&#064;Service\u3001&#064;Controller\u6807\u6ce8\u7684\u7c7b&#xff09;\u90fd\u662f\u901a\u8fc7\u6b64\u6b65\u9aa4\u6279\u91cf\u6ce8\u518c\u5230\u5bb9\u5668\u4e2d\u7684\u3002<\/p>\n<h4>\u6b65\u9aa46&#xff1a;registerBeanPostProcessors()\u2014\u2014\u6ce8\u518cBean\u540e\u7f6e\u5904\u7406\u5668<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u5c06\u5bb9\u5668\u4e2d\u6240\u6709BeanPostProcessor\u6ce8\u518c\u5230BeanFactory\u4e2d&#xff0c;\u540e\u7eedBean\u521b\u5efa\u65f6\u4f1a\u8c03\u7528\u8fd9\u4e9b\u540e\u7f6e\u5904\u7406\u5668&#xff0c;\u5e72\u9884Bean\u7684\u521d\u59cb\u5316\u6d41\u7a0b&#xff08;\u5982\u81ea\u52a8\u6ce8\u5165\u3001\u4ee3\u7406\u521b\u5efa\u3001\u5faa\u73af\u4f9d\u8d56\u5904\u7406&#xff09;\u3002<\/p>\n<li>\n<p>\u83b7\u53d6\u6240\u6709BeanPostProcessor&#xff1a;\u4eceBeanFactory\u4e2d\u83b7\u53d6\u6240\u6709\u5b9e\u73b0BeanPostProcessor\u63a5\u53e3\u7684BeanDefinition\u3002<\/p>\n<\/li>\n<li>\n<p>\u6309\u4f18\u5148\u7ea7\u6ce8\u518c&#xff1a;<\/p>\n<li>\n<p>\u5148\u6ce8\u518c\u5b9e\u73b0PriorityOrdered\u63a5\u53e3\u7684BeanPostProcessor\u3002<\/p>\n<\/li>\n<li>\n<p>\u518d\u6ce8\u518c\u5b9e\u73b0Ordered\u63a5\u53e3\u7684BeanPostProcessor\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e\u6ce8\u518c\u65e0\u4f18\u5148\u7ea7\u7684BeanPostProcessor\u3002<\/p>\n<\/li>\n<li>\n<p>\u5355\u72ec\u6ce8\u518cMergedBeanDefinitionPostProcessor\u7c7b\u578b\u7684\u540e\u7f6e\u5904\u7406\u5668&#xff08;\u7528\u4e8e\u5408\u5e76BeanDefinition\u5143\u4fe1\u606f&#xff09;\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u6ce8\u518cApplicationListenerDetector&#xff1a;\u786e\u4fdd\u76d1\u542c\u5668Bean\u88ab\u6b63\u786e\u8bc6\u522b\u5e76\u6ce8\u518c\u3002<\/p>\n<\/li>\n<p>\u6269\u5c55&#xff1a;\u65e0\u4ee3\u7406\u6a21\u5f0f\u4e0b&#xff0c;\u5bb9\u5668\u9ed8\u8ba4\u6ce8\u518c6\u4e2aBeanPostProcessor&#xff0c;\u5206\u522b\u662f&#xff1a;ApplicationContextAwareProcessor\u3001ConfigurationClassPostProcessorsAwareBeanPostProcessor\u3001PostProcessorRegistrationDelegate\u3001CommonAnnotationBeanPostProcessor\u3001AutowiredAnnotationBeanPostProcessor\u3001ApplicationListenerDetector\u3002<\/p>\n<h4>\u6b65\u9aa47&#xff1a;initMessageSource()\u2014\u2014\u521d\u59cb\u5316\u56fd\u9645\u5316\u7ec4\u4ef6<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u521d\u59cb\u5316MessageSource\u7ec4\u4ef6&#xff0c;\u652f\u6301\u56fd\u9645\u5316\u6d88\u606f\u7ed1\u5b9a\u548c\u89e3\u6790&#xff08;\u5982\u591a\u8bed\u8a00\u914d\u7f6e\u6587\u4ef6&#xff09;\u3002<\/p>\n<li>\n<p>\u68c0\u67e5\u5bb9\u5668\u4e2d\u662f\u5426\u5b58\u5728id\u4e3a\u201cmessageSource\u201d\u4e14\u7c7b\u578b\u4e3aMessageSource\u7684Bean&#xff0c;\u5b58\u5728\u5219\u76f4\u63a5\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u5b58\u5728\u5219\u521b\u5efaDelegatingMessageSource&#xff08;\u9ed8\u8ba4\u5b9e\u73b0&#xff09;&#xff0c;\u4f5c\u4e3a\u9ed8\u8ba4\u7684MessageSource\u7ec4\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06MessageSource\u6ce8\u518c\u5230BeanFactory\u4e2d&#xff0c;\u4f9b\u5176\u4ed6Bean\u901a\u8fc7&#064;Autowired\u81ea\u52a8\u6ce8\u5165&#xff0c;\u7528\u4e8e\u83b7\u53d6\u56fd\u9645\u5316\u6d88\u606f\u3002<\/p>\n<\/li>\n<h4>\u6b65\u9aa48&#xff1a;initApplicationEventMulticaster()\u2014\u2014\u521d\u59cb\u5316\u4e8b\u4ef6\u6d3e\u53d1\u5668<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u521d\u59cb\u5316\u4e8b\u4ef6\u6d3e\u53d1\u5668&#xff0c;\u8d1f\u8d23\u4e8b\u4ef6\u7684\u53d1\u5e03\u548c\u76d1\u542c\u5668\u7684\u7ba1\u7406&#xff0c;\u652f\u6491Spring\u7684\u4e8b\u4ef6\u9a71\u52a8\u6a21\u578b\u3002<\/p>\n<li>\n<p>\u68c0\u67e5\u5bb9\u5668\u4e2d\u662f\u5426\u5b58\u5728\u81ea\u5b9a\u4e49\u7684ApplicationEventMulticaster Bean&#xff0c;\u5b58\u5728\u5219\u76f4\u63a5\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0d\u5b58\u5728\u5219\u521b\u5efaSimpleApplicationEventMulticaster&#xff08;\u9ed8\u8ba4\u5b9e\u73b0&#xff09;&#xff0c;\u4f5c\u4e3a\u4e8b\u4ef6\u6d3e\u53d1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c06\u4e8b\u4ef6\u6d3e\u53d1\u5668\u6ce8\u518c\u5230BeanFactory\u4e2d&#xff0c;\u4f9b\u5176\u4ed6\u7ec4\u4ef6\u53d1\u5e03\u548c\u63a5\u6536\u4e8b\u4ef6\u3002<\/p>\n<\/li>\n<h4>\u6b65\u9aa49&#xff1a;onRefresh()\u2014\u2014\u5b50\u7c7b\u6269\u5c55\u5237\u65b0\u903b\u8f91<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u7559\u7ed9\u5b50\u7c7b\u91cd\u5199&#xff0c;\u5728\u5bb9\u5668\u5237\u65b0\u8fc7\u7a0b\u4e2d\u6dfb\u52a0\u81ea\u5b9a\u4e49\u903b\u8f91\u3002\u4f8b\u5982&#xff0c;Spring MVC\u7684WebApplicationContext\u4f1a\u91cd\u5199\u6b64\u65b9\u6cd5&#xff0c;\u521d\u59cb\u5316DispatcherServlet&#xff1b;Spring Boot\u7684EmbeddedWebApplicationContext\u4f1a\u91cd\u5199\u6b64\u65b9\u6cd5&#xff0c;\u542f\u52a8\u5d4c\u5165\u5f0f\u670d\u52a1\u5668&#xff08;Tomcat\u3001Jetty&#xff09;\u3002<\/p>\n<h4>\u6b65\u9aa410&#xff1a;registerListeners()\u2014\u2014\u6ce8\u518c\u76d1\u542c\u5668<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u5c06\u5bb9\u5668\u4e2d\u7684ApplicationListener\u6ce8\u518c\u5230\u4e8b\u4ef6\u6d3e\u53d1\u5668\u4e2d&#xff0c;\u5e76\u6d3e\u53d1\u65e9\u671f\u4e8b\u4ef6\u3002<\/p>\n<li>\n<p>\u83b7\u53d6\u5bb9\u5668\u4e2d\u6240\u6709ApplicationListener\u7c7b\u578b\u7684Bean&#xff0c;\u6ce8\u518c\u5230\u4e8b\u4ef6\u6d3e\u53d1\u5668\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u6d3e\u53d1\u6b65\u9aa41\u4e2d\u4fdd\u5b58\u7684\u65e9\u671f\u4e8b\u4ef6&#xff08;earlyApplicationEvents&#xff09;&#xff0c;\u786e\u4fdd\u65e9\u671f\u4e8b\u4ef6\u88ab\u6b63\u786e\u5904\u7406\u3002<\/p>\n<\/li>\n<h4>\u6b65\u9aa411&#xff1a;finishBeanFactoryInitialization()\u2014\u2014\u521d\u59cb\u5316\u975e\u61d2\u52a0\u8f7d\u5355\u4f8bBean<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u521d\u59cb\u5316\u5bb9\u5668\u4e2d\u6240\u6709\u975e\u61d2\u52a0\u8f7d\u7684\u5355\u4f8bBean&#xff0c;\u5b8c\u6210Bean\u7684\u521b\u5efa\u3001\u4f9d\u8d56\u6ce8\u5165\u3001\u521d\u59cb\u5316\u65b9\u6cd5\u6267\u884c\u7b49\u6838\u5fc3\u64cd\u4f5c&#xff0c;\u662frefresh()\u65b9\u6cd5\u4e2d\u6700\u6838\u5fc3\u7684\u6b65\u9aa4\u4e4b\u4e00\u3002<\/p>\n<li>\n<p>\u83b7\u53d6\u6240\u6709BeanDefinition\u540d\u79f0&#xff1a;\u904d\u5386BeanFactory\u4e2d\u6ce8\u518c\u7684\u6240\u6709BeanDefinition\u7684\u540d\u79f0\u3002<\/p>\n<\/li>\n<li>\n<p>\u5408\u5e76BeanDefinition&#xff1a;\u5c06BeanDefinition\u4e0e\u5176\u7236\u7c7bBeanDefinition\u5408\u5e76&#xff0c;\u751f\u6210RootBeanDefinition&#xff08;\u5305\u542b\u5b8c\u6574\u7684Bean\u5143\u4fe1\u606f&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b5b\u9009\u5355\u4f8b\u3001\u975e\u62bd\u8c61\u3001\u975e\u61d2\u52a0\u8f7dBean&#xff1a;\u4ec5\u5bf9\u6ee1\u8db3\u201c\u5355\u4f8b&#xff08;singleton&#xff09;\u3001\u975e\u62bd\u8c61&#xff08;abstract&#061;false&#xff09;\u3001\u975e\u61d2\u52a0\u8f7d&#xff08;lazy-init&#061;false&#xff09;\u201d\u6761\u4ef6\u7684Bean\u6267\u884c\u521d\u59cb\u5316\u3002<\/p>\n<\/li>\n<li>\n<p>Bean\u521b\u5efa\u6d41\u7a0b&#xff1a;\u901a\u8fc7getBean()\u65b9\u6cd5\u89e6\u53d1Bean\u521b\u5efa&#xff0c;\u6838\u5fc3\u6d41\u7a0b\u5305\u62ec&#xff1a;<\/p>\n<li>\n<p>\u5b9e\u4f8b\u5316Bean&#xff08;\u901a\u8fc7\u6784\u9020\u65b9\u6cd5\u521b\u5efa\u5bf9\u8c61&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5c5e\u6027\u6ce8\u5165&#xff08;&#064;Autowired\u3001&#064;Resource\u7b49\u6ce8\u89e3\u7684\u81ea\u52a8\u6ce8\u5165&#xff0c;\u5904\u7406\u5faa\u73af\u4f9d\u8d56&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u524d&#xff08;BeanPostProcessor#postProcessBeforeInitialization&#xff09;&#xff1a;\u5982AOP\u4ee3\u7406\u521b\u5efa\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u65b9\u6cd5\u6267\u884c&#xff08;&#064;PostConstruct\u6ce8\u89e3\u65b9\u6cd5\u3001InitializingBean#afterPropertiesSet()\u3001\u81ea\u5b9a\u4e49init-method&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u521d\u59cb\u5316\u540e&#xff08;BeanPostProcessor#postProcessAfterInitialization&#xff09;&#xff1a;\u5982AOP\u4ee3\u7406\u589e\u5f3a\u3002<\/p>\n<\/li>\n<\/li>\n<li>\n<p>\u6267\u884cSmartInitializingSingleton#afterSingletonsInstantiated()&#xff1a;\u6240\u6709\u5355\u4f8bBean\u521d\u59cb\u5316\u5b8c\u6210\u540e&#xff0c;\u6267\u884c\u6b64\u65b9\u6cd5&#xff08;\u6269\u5c55\u70b9&#xff0c;\u7528\u4e8e\u540e\u7eed\u5904\u7406&#xff09;\u3002<\/p>\n<\/li>\n<p>\u6269\u5c55&#xff1a;\u61d2\u52a0\u8f7dBean&#xff08;&#064;Lazy\u6ce8\u89e3&#xff09;\u4f1a\u5728\u9996\u6b21\u8c03\u7528getBean()\u65f6\u521d\u59cb\u5316&#xff0c;\u800c\u975e\u6b64\u6b65\u9aa4\u3002<\/p>\n<h4>\u6b65\u9aa412&#xff1a;finishRefresh()\u2014\u2014\u5bb9\u5668\u5237\u65b0\u5b8c\u6210<\/h4>\n<p>\u6838\u5fc3\u76ee\u7684&#xff1a;\u5b8c\u6210\u5bb9\u5668\u5237\u65b0\u7684\u6536\u5c3e\u5de5\u4f5c&#xff0c;\u53d1\u5e03\u5bb9\u5668\u5237\u65b0\u5b8c\u6210\u4e8b\u4ef6&#xff0c;\u521d\u59cb\u5316\u751f\u547d\u5468\u671f\u5904\u7406\u5668\u3002<\/p>\n<li>\n<p>initLifecycleProcessor()&#xff1a;\u521d\u59cb\u5316\u751f\u547d\u5468\u671f\u5904\u7406\u5668&#xff08;LifecycleProcessor&#xff09;&#xff0c;\u9ed8\u8ba4\u521b\u5efaDefaultLifecycleProcessor&#xff0c;\u7528\u4e8e\u7ba1\u7406Bean\u7684\u751f\u547d\u5468\u671f&#xff08;start\u3001stop\u65b9\u6cd5&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u89e6\u53d1LifecycleProcessor#onRefresh()&#xff1a;\u56de\u8c03\u6240\u6709\u5b9e\u73b0Lifecycle\u63a5\u53e3\u7684Bean\u7684start()\u65b9\u6cd5\u3002<\/p>\n<\/li>\n<li>\n<p>\u53d1\u5e03ContextRefreshedEvent\u4e8b\u4ef6&#xff1a;\u544a\u77e5\u6240\u6709\u76d1\u542c\u5668\u5bb9\u5668\u5df2\u5237\u65b0\u5b8c\u6210&#xff0c;Bean\u53ef\u6b63\u5e38\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>\u6ce8\u518c\u5bb9\u5668\u5230LiveBeansView&#xff1a;\u7528\u4e8e\u76d1\u63a7\u5bb9\u5668\u4e2d\u7684Bean\u72b6\u6001&#xff08;\u4ec5\u5f00\u53d1\u73af\u5883\u751f\u6548&#xff09;\u3002<\/p>\n<\/li>\n<h3>3.3 \u5faa\u73af\u4f9d\u8d56\u95ee\u9898<\/h3>\n<ul>\n<li>\n<p>\u5faa\u73af\u4f9d\u8d56\u5904\u7406&#xff1a;Spring\u901a\u8fc7\u201c\u4e09\u7ea7\u7f13\u5b58\u201d\u89e3\u51b3\u5355\u4f8bBean\u7684\u5faa\u73af\u4f9d\u8d56&#xff0c;\u6838\u5fc3\u662f\u63d0\u524d\u66b4\u9732\u672a\u521d\u59cb\u5316\u5b8c\u6210\u7684Bean\u5b9e\u4f8b&#xff0c;\u5728\u6b65\u9aa411\u7684\u5c5e\u6027\u6ce8\u5165\u9636\u6bb5\u4f7f\u7528\u3002<\/p>\n<\/li>\n<li>\n<p>1. \u4ec0\u4e48\u662f\u5faa\u73af\u4f9d\u8d56&#xff1a;\u4e24\u4e2a\u6216\u591a\u4e2aBean\u76f8\u4e92\u4f9d\u8d56\u5f62\u6210\u95ed\u73af&#xff0c;\u5982A\u4f9d\u8d56B&#xff0c;B\u53c8\u4f9d\u8d56A&#xff1b;\u6216A\u4f9d\u8d56B\u3001B\u4f9d\u8d56C\u3001C\u4f9d\u8d56A\u3002<\/p>\n<\/li>\n<li>\n<p>2. \u652f\u6301\u8303\u56f4&#xff1a;\u4ec5\u652f\u6301\u5355\u4f8bBean\u7684\u5faa\u73af\u4f9d\u8d56&#xff0c;\u539f\u578b&#xff08;Prototype&#xff09;Bean\u4e0d\u652f\u6301&#xff08;\u6bcf\u6b21\u83b7\u53d6\u90fd\u65b0\u5efa\u5b9e\u4f8b&#xff0c;\u65e0\u6cd5\u63d0\u524d\u66b4\u9732&#xff09;&#xff0c;\u6784\u9020\u65b9\u6cd5\u6ce8\u5165\u7684\u5355\u4f8bBean\u4e5f\u4e0d\u652f\u6301&#xff08;\u5b9e\u4f8b\u5316\u524d\u5c31\u9700\u8981\u4f9d\u8d56\u5bf9\u8c61&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>3. \u4e09\u7ea7\u7f13\u5b58\u6838\u5fc3\u673a\u5236&#xff1a;<\/p>\n<\/li>\n<li>\n<p>\u4e00\u7ea7\u7f13\u5b58&#xff08;singletonObjects&#xff09;&#xff1a;\u5b58\u50a8\u5b8c\u5168\u521d\u59cb\u5316\u5b8c\u6210\u7684\u5355\u4f8bBean&#xff0c;\u4f9b\u5916\u90e8\u83b7\u53d6\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e8c\u7ea7\u7f13\u5b58&#xff08;earlySingletonObjects&#xff09;&#xff1a;\u5b58\u50a8\u63d0\u524d\u66b4\u9732\u7684\u3001\u672a\u5b8c\u6210\u5c5e\u6027\u6ce8\u5165\u548c\u521d\u59cb\u5316\u7684\u5355\u4f8bBean\u5b9e\u4f8b&#xff0c;\u7528\u4e8e\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u65f6\u7684\u4e34\u65f6\u83b7\u53d6\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e09\u7ea7\u7f13\u5b58&#xff08;singletonFactories&#xff09;&#xff1a;\u5b58\u50a8Bean\u7684\u5b9e\u4f8b\u5de5\u5382&#xff08;ObjectFactory&#xff09;&#xff0c;\u7528\u4e8e\u5ef6\u8fdf\u521b\u5efaBean\u7684\u65e9\u671f\u5b9e\u4f8b&#xff08;\u82e5Bean\u9700\u8981AOP\u4ee3\u7406&#xff0c;\u53ef\u901a\u8fc7\u5de5\u5382\u751f\u6210\u4ee3\u7406\u5b9e\u4f8b\u540e\u66b4\u9732&#xff09;\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u5177\u4f53\u6d41\u7a0b:<\/p>\n<li>\n<p>A\u5f00\u59cb\u5b9e\u4f8b\u5316&#xff08;\u901a\u8fc7\u6784\u9020\u65b9\u6cd5\u521b\u5efa\u5bf9\u8c61&#xff09;&#xff0c;\u672a\u5b8c\u6210\u5c5e\u6027\u6ce8\u5165\u548c\u521d\u59cb\u5316&#xff0c;\u5c06A\u7684\u5b9e\u4f8b\u5de5\u5382\u5b58\u5165\u4e09\u7ea7\u7f13\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>A\u9700\u8981\u6ce8\u5165B&#xff0c;\u5bb9\u5668\u5c1d\u8bd5\u83b7\u53d6B&#xff0c;\u53d1\u73b0B\u672a\u5b9e\u4f8b\u5316&#xff0c;\u5f00\u59cb\u5b9e\u4f8b\u5316B\u3002<\/p>\n<\/li>\n<li>\n<p>B\u5b9e\u4f8b\u5316\u540e&#xff0c;\u9700\u8981\u6ce8\u5165A&#xff0c;\u5bb9\u5668\u4ece\u4e09\u7ea7\u7f13\u5b58\u83b7\u53d6A\u7684\u5b9e\u4f8b\u5de5\u5382&#xff0c;\u751f\u6210A\u7684\u65e9\u671f\u5b9e\u4f8b&#xff08;\u82e5\u6709AOP\u4ee3\u7406\u5219\u751f\u6210\u4ee3\u7406\u5b9e\u4f8b&#xff09;&#xff0c;\u5b58\u5165\u4e8c\u7ea7\u7f13\u5b58&#xff0c;\u5220\u9664\u4e09\u7ea7\u7f13\u5b58\u4e2d\u7684A\u5de5\u5382\u3002<\/p>\n<\/li>\n<li>\n<p>B\u6ce8\u5165A\u7684\u65e9\u671f\u5b9e\u4f8b&#xff0c;\u5b8c\u6210\u5c5e\u6027\u6ce8\u5165\u3001\u521d\u59cb\u5316&#xff0c;\u6210\u4e3a\u5b8c\u6574Bean&#xff0c;\u5b58\u5165\u4e00\u7ea7\u7f13\u5b58\u3002<\/p>\n<\/li>\n<li>\n<p>A\u83b7\u53d6\u5230\u4e00\u7ea7\u7f13\u5b58\u4e2d\u7684\u5b8c\u6574B\u5b9e\u4f8b&#xff0c;\u6ce8\u5165\u5b8c\u6210&#xff0c;\u7ee7\u7eed\u6267\u884c\u521d\u59cb\u5316\u6d41\u7a0b&#xff0c;\u6700\u7ec8\u6210\u4e3a\u5b8c\u6574Bean&#xff0c;\u5b58\u5165\u4e00\u7ea7\u7f13\u5b58&#xff0c;\u5220\u9664\u4e8c\u7ea7\u7f13\u5b58\u4e2d\u7684A\u65e9\u671f\u5b9e\u4f8b\u3002<\/p>\n<\/li>\n<ul>\n<li>\n<p>AOP\u7684\u89e6\u53d1\u65f6\u673a&#xff1a;AOP\u4ee3\u7406\u7684\u521b\u5efa\u53d1\u751f\u5728Bean\u521d\u59cb\u5316\u524d&#xff08;postProcessBeforeInitialization&#xff09;&#xff0c;\u589e\u5f3a\u903b\u8f91\u5728\u521d\u59cb\u5316\u540e&#xff08;postProcessAfterInitialization&#xff09;\u5b8c\u6210\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e8b\u4ef6\u9a71\u52a8\u6a21\u578b&#xff1a;Spring\u7684\u4e8b\u4ef6\u6d3e\u53d1\u57fa\u4e8e\u89c2\u5bdf\u8005\u6a21\u5f0f&#xff0c;\u901a\u8fc7ApplicationEventMulticaster\u8fde\u63a5\u4e8b\u4ef6\u53d1\u5e03\u8005\u548c\u76d1\u542c\u5668&#xff0c;\u652f\u6301\u540c\u6b65\/\u5f02\u6b65\u4e8b\u4ef6\u6d3e\u53d1\u3002<\/p>\n<\/li>\n<\/ul>\n<h2>\u4e94\u3001\u6574\u4f53\u603b\u7ed3<\/h2>\n<h3>5.1 \u6838\u5fc3\u6d41\u7a0b\u68b3\u7406<\/h3>\n<p>Spring\u5bb9\u5668\u542f\u52a8\u7684\u672c\u8d28\u662f\u300c\u4ece\u914d\u7f6e\u5230Bean\u5b9e\u4f8b\u5316\u7684\u5168\u94fe\u8def\u6d41\u7a0b\u300d&#xff1a;\u901a\u8fc7\u521d\u59cb\u5316\u5bb9\u5668\u7ec4\u4ef6&#xff08;BeanFactory\u3001\u89e3\u6790\u5668\u3001\u626b\u63cf\u5668&#xff09;\u642d\u5efa\u57fa\u7840\u73af\u5883&#xff0c;\u6ce8\u518c\u914d\u7f6e\u7c7b\u548c\u5185\u7f6e\u7ec4\u4ef6\u7684BeanDefinition&#xff0c;\u518d\u901a\u8fc7refresh()\u65b9\u6cd5\u768412\u4e2a\u6b65\u9aa4\u5b8c\u6210BeanDefinition\u89e3\u6790\u3001\u540e\u7f6e\u5904\u7406\u5668\u6267\u884c\u3001Bean\u521d\u59cb\u5316\u3001\u7ec4\u4ef6\u88c5\u914d&#xff0c;\u6700\u7ec8\u5f62\u6210\u53ef\u7528\u7684Spring\u5bb9\u5668\u3002<\/p>\n<h3>5.2\u00a0\u6838\u5fc3\u539f\u5219\u63d0\u70bc<\/h3>\n<p>Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b\u59cb\u7ec8\u56f4\u7ed5\u300c\u89e3\u8026\u3001\u6269\u5c55\u3001\u590d\u7528\u300d\u4e09\u5927\u539f\u5219&#xff0c;\u901a\u8fc7\u5927\u91cf\u6269\u5c55\u70b9&#xff08;\u540e\u7f6e\u5904\u7406\u5668\u3001Aware\u63a5\u53e3\u3001\u4e8b\u4ef6\u673a\u5236&#xff09;\u5141\u8bb8\u7528\u6237\u5b9a\u5236\u5316\u5f00\u53d1&#xff0c;\u540c\u65f6\u901a\u8fc7\u7edf\u4e00\u7684\u6d41\u7a0b\u7ba1\u7406\u786e\u4fdd\u5bb9\u5668\u7684\u7a33\u5b9a\u6027\u548c\u4e00\u81f4\u6027\u3002\u7406\u89e3Spring\u542f\u52a8\u6d41\u7a0b&#xff0c;\u662f\u638c\u63e1Spring\u5e95\u5c42\u539f\u7406\u3001\u6392\u67e5\u542f\u52a8\u6545\u969c\u3001\u8fdb\u884c\u9ad8\u7ea7\u5b9a\u5236\u5316\u5f00\u53d1\u7684\u57fa\u7840\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u57fa\u4e8eSpring Framework\u6e90\u7801&#xff0c;\u4ee5\u300cAnnotationConfigApplicationContext\u300d\u4e3a\u5165\u53e3&#xff08;Java Config\u65b9\u5f0f&#xff09;&#xff0c;\u5168\u9762\u62c6\u89e3Spring\u5bb9\u5668\u542f\u52a8\u7684\u5b8c\u6574\u6d41\u7a0b&#xff0c;\u5305\u542b\u521d\u59cb\u5316\u3001\u914d\u7f6e\u7c7b\u6ce8\u518c\u3001\u5bb9\u5668\u5237\u65b0\u4e09\u5927\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u7ed3\u5408\u6e90\u7801\u9010\u53e5\u5206\u6790\u5173\u952e\u903b\u8f91&#xff0c;\u8865\u5145\u6838\u5fc3\u6982\u5ff5\u3001\u6269\u5c55\u77e5\u8bc6\u70b9\u53ca\u5b9e\u6218\u5173\u8054&#xff0c;\u52a9\u529b\u6df1\u5165\u7406\u89e3Spring\u5e95\u5c42\u539f\u7406\u3002<br \/>\n\u6838\u5fc3\u524d\u63d0&#xff1a;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,101,292],"topic":[],"class_list":["post-64584","post","type-post","status-publish","format-standard","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\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \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\/64584.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u672c\u6587\u57fa\u4e8eSpring Framework\u6e90\u7801&#xff0c;\u4ee5\u300cAnnotationConfigApplicationContext\u300d\u4e3a\u5165\u53e3&#xff08;Java Config\u65b9\u5f0f&#xff09;&#xff0c;\u5168\u9762\u62c6\u89e3Spring\u5bb9\u5668\u542f\u52a8\u7684\u5b8c\u6574\u6d41\u7a0b&#xff0c;\u5305\u542b\u521d\u59cb\u5316\u3001\u914d\u7f6e\u7c7b\u6ce8\u518c\u3001\u5bb9\u5668\u5237\u65b0\u4e09\u5927\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u7ed3\u5408\u6e90\u7801\u9010\u53e5\u5206\u6790\u5173\u952e\u903b\u8f91&#xff0c;\u8865\u5145\u6838\u5fc3\u6982\u5ff5\u3001\u6269\u5c55\u77e5\u8bc6\u70b9\u53ca\u5b9e\u6218\u5173\u8054&#xff0c;\u52a9\u529b\u6df1\u5165\u7406\u89e3Spring\u5e95\u5c42\u539f\u7406\u3002 \u6838\u5fc3\u524d\u63d0&#xff1a;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/64584.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-23T11:40:21+00:00\" \/>\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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64584.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/64584.html\",\"name\":\"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-01-23T11:40:21+00:00\",\"dateModified\":\"2026-01-23T11:40:21+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/64584.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/64584.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/64584.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b\"}]},{\"@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\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \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\/64584.html","og_locale":"zh_CN","og_type":"article","og_title":"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u672c\u6587\u57fa\u4e8eSpring Framework\u6e90\u7801&#xff0c;\u4ee5\u300cAnnotationConfigApplicationContext\u300d\u4e3a\u5165\u53e3&#xff08;Java Config\u65b9\u5f0f&#xff09;&#xff0c;\u5168\u9762\u62c6\u89e3Spring\u5bb9\u5668\u542f\u52a8\u7684\u5b8c\u6574\u6d41\u7a0b&#xff0c;\u5305\u542b\u521d\u59cb\u5316\u3001\u914d\u7f6e\u7c7b\u6ce8\u518c\u3001\u5bb9\u5668\u5237\u65b0\u4e09\u5927\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u7ed3\u5408\u6e90\u7801\u9010\u53e5\u5206\u6790\u5173\u952e\u903b\u8f91&#xff0c;\u8865\u5145\u6838\u5fc3\u6982\u5ff5\u3001\u6269\u5c55\u77e5\u8bc6\u70b9\u53ca\u5b9e\u6218\u5173\u8054&#xff0c;\u52a9\u529b\u6df1\u5165\u7406\u89e3Spring\u5e95\u5c42\u539f\u7406\u3002 \u6838\u5fc3\u524d\u63d0&#xff1a;","og_url":"https:\/\/www.wsisp.com\/helps\/64584.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-01-23T11:40:21+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/64584.html","url":"https:\/\/www.wsisp.com\/helps\/64584.html","name":"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-01-23T11:40:21+00:00","dateModified":"2026-01-23T11:40:21+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/64584.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/64584.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/64584.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Spring\u5bb9\u5668\u542f\u52a8\u6d41\u7a0b"}]},{"@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\/64584","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=64584"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/64584\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=64584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=64584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=64584"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=64584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}