{"id":89098,"date":"2026-08-02T12:49:02","date_gmt":"2026-08-02T04:49:02","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/89098.html"},"modified":"2026-08-02T12:49:02","modified_gmt":"2026-08-02T04:49:02","slug":"18-%e9%9d%a2%e8%af%95%e5%ae%98%ef%bc%9aspring-bean-%e7%9a%84%e7%94%9f%e5%91%bd%e5%91%a8%e6%9c%9f%e5%88%b0%e5%ba%95%e6%9c%89%e5%a4%9a%e9%95%bf%ef%bc%9f%e6%88%91%e7%9c%8b%e8%bf%87%e6%ba%90%e7%a0%81","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/89098.html","title":{"rendered":"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d"},"content":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u89e3\u6790 Spring Bean \u751f\u547d\u5468\u671f\u7684 13 \u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u4ece\u5b9e\u4f8b\u5316\u3001\u5c5e\u6027\u6ce8\u5165\u5230\u521d\u59cb\u5316\u524d\u540e\u7684 BeanPostProcessor \u94a9\u5b50\u673a\u5236\u3002\u91cd\u70b9\u63ed\u793a\u4e86 AOP \u4ee3\u7406\u5728 postProcessAfterInitialization \u9636\u6bb5\u521b\u5efa\u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u4ee5\u53ca\u4e09\u7ea7\u7f13\u5b58\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u7684\u5173\u952e\u8bbe\u8ba1\u3002\u6587\u7ae0\u8fd8\u5bf9\u6bd4\u4e86 BeanPostProcessor \u4e0e BeanFactoryPostProcessor \u7684\u533a\u522b&#xff0c;\u5e76\u4ecb\u7ecd\u4e86 &#064;PostConstruct\u3001SmartInitializingSingleton \u7b49\u6269\u5c55\u94a9\u5b50&#xff0c;\u5e2e\u52a9\u8bfb\u8005\u4ece\u6e90\u7801\u5c42\u9762\u638c\u63e1 Spring \u5bb9\u5668\u7684\u6838\u5fc3\u5de5\u4f5c\u673a\u5236\u3002<\/p>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044900-6a6ecc3c5cced.png\" \/><\/p>\n<p>&#034;Spring Bean \u7684\u751f\u547d\u5468\u671f\u662f\u4ec0\u4e48&#xff1f;&#034;<\/p>\n<p>\u8fd9\u9053\u9898\u9762\u8bd5\u9891\u7387\u4e4b\u9ad8&#xff0c;\u51e0\u4e4e\u8ddf&#034;HashMap \u539f\u7406&#034;\u4e00\u4e2a\u7ea7\u522b\u3002\u4f46\u4f60\u4ed4\u7ec6\u56de\u5fc6\u4e00\u4e0b\u2014\u2014\u5927\u90e8\u5206\u4eba\u7684\u56de\u7b54\u662f\u4e0d\u662f\u5c31\u4e09\u53e5\u8bdd&#xff1a;\u5b9e\u4f8b\u5316\u3001\u5c5e\u6027\u6ce8\u5165\u3001\u521d\u59cb\u5316&#xff1f;<\/p>\n<p>\u8fd9\u6ca1\u9519&#xff0c;\u4f46\u4f60\u6f0f\u6389\u4e86\u4e00\u6574\u5c42\u4e1c\u897f\u3002<\/p>\n<p>\u9762\u8bd5\u5b98\u771f\u6b63\u60f3\u542c\u7684&#xff0c;\u662f\u4f60\u77e5\u4e0d\u77e5\u9053BeanPostProcessor\u8fd9\u4e2a\u673a\u5236\u2014\u2014\u5b83\u624d\u662f\u8d2f\u7a7f Spring Bean \u751f\u547d\u5468\u671f\u7684\u7075\u9b42\u3002\u6ca1\u6709\u5b83&#xff0c;AOP \u5207\u4e0d\u8fdb\u53bb\u3001\u4e8b\u52a1\u7ba1\u7406\u8dd1\u4e0d\u8d77\u6765\u3001&#064;Autowired \u6839\u672c\u4e0d\u4f1a\u5de5\u4f5c\u3002BeanPostProcessor \u662f\u5728 Bean \u521d\u59cb\u5316\u524d\u540e\u63d2\u5165\u81ea\u5b9a\u4e49\u903b\u8f91\u7684\u94a9\u5b50&#xff0c;\u5b83\u7684 intercept \u80fd\u529b\u662f Spring \u6240\u6709\u6269\u5c55\u529f\u80fd\u7684\u57fa\u7840\u3002<\/p>\n<p>\u4eca\u5929\u5c31\u4ece\u5934\u5230\u5c3e\u8fc7\u4e00\u904d Spring Bean \u7684\u751f\u547d\u5468\u671f&#xff0c;\u6bcf\u4e00\u9636\u6bb5\u6211\u544a\u8bc9\u4f60\u6e90\u7801\u5728\u54ea\u513f\u3001\u505a\u4e86\u4ec0\u4e48\u3001\u6709\u4ec0\u4e48\u7528\u3002<\/p>\n<hr \/>\n<h3>\u5148\u628a\u6574\u4f53\u6d41\u7a0b\u753b\u51fa\u6765<\/h3>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044900-6a6ecc3cc6987.png\" \/><\/p>\n<p>\u4e00\u4e2a Bean \u4ece\u8bde\u751f\u5230\u9500\u6bc1&#xff0c;\u7406\u8bba\u4e0a\u7ecf\u5386\u4e94\u4e2a\u9636\u6bb5\u3002\u4f46 Spring \u5728\u8fd9\u4e94\u4e2a\u9636\u6bb5\u91cc\u5d4c\u5165\u4e86\u5927\u91cf\u5e72\u9884\u70b9\u3002\u628a\u5e72\u9884\u70b9\u52a0\u4e0a&#xff0c;\u5b9e\u9645\u7684\u6b65\u9aa4\u662f 13 \u6b65&#xff1a;<\/p>\n<p>1. \u5b9e\u4f8b\u5316&#xff08;\u53cd\u5c04\u521b\u5efa\u5bf9\u8c61&#xff09;<br \/>\n2. \u5c5e\u6027\u6ce8\u5165&#xff08;\u8bbe\u7f6e\u5404\u79cd\u5c5e\u6027\u503c&#xff09;<br \/>\n3. BeanNameAware.setBeanName()<br \/>\n4. BeanClassLoaderAware.setBeanClassLoader()<br \/>\n5. BeanFactoryAware.setBeanFactory()<br \/>\n6. BeanPostProcessor.postProcessBeforeInitialization()<br \/>\n7. InitializingBean.afterPropertiesSet()<br \/>\n8. \u81ea\u5b9a\u4e49 init-method<br \/>\n9. BeanPostProcessor.postProcessAfterInitialization()  \u2190 &#x1f525; AOP\u5728\u8fd9\u6b65<br \/>\n10. Bean \u51c6\u5907\u5c31\u7eea&#xff0c;\u53ef\u4ee5\u7528\u4e86<br \/>\n&#8230;<br \/>\n11. DisposableBean.destroy()<br \/>\n12. \u81ea\u5b9a\u4e49 destroy-method<br \/>\n13. Bean \u9500\u6bc1<\/p>\n<p>\u8fd9\u91cc\u9762\u6700\u6838\u5fc3\u7684\u662f\u7b2c 9 \u6b65\u2014\u2014postProcessAfterInitialization()\u3002AOP \u7684\u4ee3\u7406\u5bf9\u8c61\u5c31\u662f\u5728\u8fd9\u6b65\u521b\u5efa\u7684\u3002Spring \u7684 AbstractAutoProxyCreator \u5b9e\u73b0\u4e86 BeanPostProcessor&#xff0c;\u5728 postProcessAfterInitialization \u91cc\u5224\u65ad\u8fd9\u4e2a Bean \u662f\u5426\u9700\u8981\u4ee3\u7406\u2014\u2014\u9700\u8981\u5c31\u521b\u5efa\u4ee3\u7406\u5bf9\u8c61\u66ff\u6362\u539f\u59cb Bean\u3002<\/p>\n<p>\u5982\u679c\u4f60\u4e0d\u7406\u89e3 Bean \u751f\u547d\u5468\u671f\u91cc\u6709\u8fd9\u4e2a\u94a9\u5b50&#xff0c;\u4f60\u6c38\u8fdc\u60f3\u4e0d\u901a&#034;\u4e3a\u4ec0\u4e48 &#064;Transactional \u5728\u6784\u9020\u5668\u91cc\u8c03\u7528\u65e0\u6548&#034;\u2014\u2014\u56e0\u4e3a\u6784\u9020\u5668\u5728\u6b65\u9aa4 1 \u5c31\u6267\u884c\u5b8c\u4e86&#xff0c;\u4e8b\u52a1\u4ee3\u7406\u5728\u6b65\u9aa4 9 \u624d\u521b\u5efa&#xff0c;\u6784\u9020\u5668\u91cc\u5f53\u7136\u62ff\u4e0d\u5230\u4ee3\u7406\u5bf9\u8c61\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e00\u6b65\u5230\u7b2c\u56db\u6b65&#xff1a;\u4ece class \u5230\u5bf9\u8c61<\/h3>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044901-6a6ecc3d2231c.png\" \/><\/p>\n<p>Spring \u5bb9\u5668\u542f\u52a8\u65f6&#xff0c;AbstractApplicationContext.refresh() \u65b9\u6cd5\u88ab\u8c03\u7528&#xff0c;\u8fd9\u4e2a\u65b9\u6cd5\u6709 13 \u4e2a\u5b50\u6b65\u9aa4&#xff0c;Bean \u7684\u751f\u547d\u5468\u671f\u53ea\u662f\u5176\u4e2d\u4e00\u73af\u3002<\/p>\n<p>\u6838\u5fc3\u5b9e\u73b0\u5728 AbstractAutowireCapableBeanFactory.doCreateBean()&#xff0c;\u6211\u628a\u5173\u952e\u6b65\u9aa4\u62c6\u51fa\u6765&#xff1a;<\/p>\n<p>\/\/ AbstractAutowireCapableBeanFactory.java \u2014 \u6838\u5fc3\u6d41\u7a0b&#xff08;\u7b80\u5316&#xff09;<br \/>\nprotected Object doCreateBean(String beanName, RootBeanDefinition mbd, Object[] args) {<br \/>\n    BeanWrapper instanceWrapper &#061; null;<br \/>\n\/\/ \u7b2c\u4e00\u6b65&#xff1a;\u5b9e\u4f8b\u5316<br \/>\n\/\/ \u901a\u8fc7\u6784\u9020\u5668\u53cd\u5c04\u521b\u5efa\u5bf9\u8c61\u5b9e\u4f8b<br \/>\nif (mbd.isSingleton()) {<br \/>\n    instanceWrapper &#061; createBeanInstance(beanName, mbd, args);<br \/>\n}<\/p>\n<p>Object bean &#061; instanceWrapper.getWrappedInstance();<\/p>\n<p>\/\/ \u7b2c\u4e8c\u6b65&#xff1a;\u65e9\u671f\u66b4\u9732&#xff08;\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56&#xff09;<br \/>\n\/\/ \u628a\u534a\u6210\u54c1\u653e\u5165\u4e09\u7ea7\u7f13\u5b58 singletonFactories<br \/>\n\/\/ \u8fd9\u6837\u522b\u7684 Bean \u5728\u5faa\u73af\u4f9d\u8d56\u65f6\u53ef\u4ee5\u62ff\u5230\u8fd9\u4e2a\u534a\u6210\u54c1<br \/>\nboolean earlySingletonExposure &#061; mbd.isSingleton() &amp;amp;&amp;amp;<br \/>\n    this.allowCircularReferences &amp;amp;&amp;amp; isSingletonCurrentlyInCreation(beanName);<br \/>\nif (earlySingletonExposure) {<br \/>\n    addSingletonFactory(beanName, () -&amp;gt; getEarlyBeanReference(beanName, mbd, bean));<br \/>\n}<\/p>\n<p>\/\/ \u7b2c\u4e09\u6b65&#xff1a;\u5c5e\u6027\u6ce8\u5165<br \/>\n\/\/ &#064;Autowired\u3001&#064;Resource\u3001&#064;Value \u90fd\u5728\u8fd9\u91cc\u5904\u7406<br \/>\npopulateBean(beanName, mbd, instanceWrapper);<\/p>\n<p>\/\/ \u7b2c\u56db\u6b65&#xff1a;\u521d\u59cb\u5316&#xff08;\u5305\u62ec Aware \u2192 Before \u2192 init \u2192 After&#xff09;<br \/>\nObject exposedObject &#061; initializeBean(beanName, exposedObject, mbd);<\/p>\n<p>return exposedObject;<br \/>\n}<\/p>\n<p>\u6ce8\u610f addSingletonFactory \u8fd9\u6b65\u2014\u2014\u628a\u672a\u5b8c\u6210\u5c5e\u6027\u6ce8\u5165\u7684\u534a\u6210\u54c1\u5bf9\u8c61\u653e\u5165\u4e09\u7ea7\u7f13\u5b58\u3002\u8fd9\u662f Spring \u89e3\u51b3\u6784\u9020\u5668\u5faa\u73af\u4f9d\u8d56\u7684\u5173\u952e\u3002\u867d\u7136\u5c5e\u6027\u6ce8\u5165\u7684\u5faa\u73af\u4f9d\u8d56\u9760\u4e8c\u7ea7\u7f13\u5b58\u5c31\u591f\u4e86&#xff0c;\u4f46\u4e09\u7ea7\u7f13\u5b58\u7684\u5b58\u5728\u662f\u56e0\u4e3a AOP \u4ee3\u7406\u9700\u8981\u5728\u521d\u59cb\u5316\u540e\u624d\u521b\u5efa\u3002\u5982\u679c\u4e0d\u7528\u4e09\u7ea7\u7f13\u5b58&#xff0c;\u5faa\u73af\u4f9d\u8d56\u65f6 AOP \u4ee3\u7406\u5bf9\u8c61\u5c31\u6ca1\u529e\u6cd5\u6b63\u786e\u521b\u5efa\u3002<\/p>\n<p>\u6bcf\u884c\u6e90\u7801\u90fd\u6709\u5b83\u7684\u610f\u4e49\u3002createBeanInstance \u4f1a\u5224\u65ad\u7528\u54ea\u4e2a\u6784\u9020\u5668\u2014\u2014\u5982\u679c\u4f60\u6709\u591a\u4e2a\u6784\u9020\u5668&#xff0c;Spring \u4f1a\u9009\u53c2\u6570\u6700\u591a\u7684\u90a3\u4e2a&#xff08;\u6216\u8005\u4f60\u660e\u786e\u6807\u6ce8\u4e86 &#064;Autowired \u7684\u90a3\u4e2a&#xff09;\u3002populateBean \u4e0d\u53ea\u662f\u8bbe\u503c&#xff0c;\u8fd8\u4f1a\u6267\u884c InstantiationAwareBeanPostProcessor \u7684\u81ea\u5b9a\u4e49\u6ce8\u5165\u903b\u8f91\u3002\u4f60\u81ea\u5b9a\u4e49\u6ce8\u89e3\u6ce8\u5165\u4e5f\u662f\u5728\u8fd9\u6b65\u901a\u8fc7\u5904\u7406\u5668\u5b9e\u73b0\u7684\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e94\u6b65\u5230\u7b2c\u4e5d\u6b65&#xff1a;\u5404\u79cd Aware \u63a5\u53e3<\/h3>\n<p>initializeBean() \u7684\u5185\u90e8\u5b9e\u73b0\u662f\u8fd9\u6837\u7684&#xff1a;<\/p>\n<p>\/\/ AbstractAutowireCapableBeanFactory.java \u2014 \u521d\u59cb\u5316\u9636\u6bb5<br \/>\nprotected Object initializeBean(String beanName, Object bean, RootBeanDefinition mbd) {<br \/>\n    \/\/ \u7b2c\u4e94\u6b65&#xff1a;\u8c03\u7528 Aware \u63a5\u53e3<br \/>\n    invokeAwareMethods(beanName, bean);<br \/>\n\/\/ \u7b2c\u516d\u6b65&#xff1a;Before \u5904\u7406\u5668<br \/>\nObject wrappedBean &#061; applyBeanPostProcessorsBeforeInitialization(bean, beanName);<\/p>\n<p>\/\/ \u7b2c\u4e03\u6b65 &#043; \u7b2c\u516b\u6b65&#xff1a;\u8c03\u7528\u521d\u59cb\u5316\u65b9\u6cd5<br \/>\ninvokeInitMethods(beanName, wrappedBean, mbd);<\/p>\n<p>\/\/ \u7b2c\u4e5d\u6b65&#xff1a;After \u5904\u7406\u5668 \u2190 AOP \u4ee3\u7406\u5728\u8fd9\u91cc<br \/>\nwrappedBean &#061; applyBeanPostProcessorsAfterInitialization(wrappedBean, beanName);<\/p>\n<p>return wrappedBean;<br \/>\n}<\/p>\n<p>invokeAwareMethods() \u91cc\u6267\u884c\u7684\u5b9e\u9645\u4e0a\u662f\u4e09\u4e2a Aware \u7684\u5224\u65ad&#xff1a;<\/p>\n<p>private void invokeAwareMethods(String beanName, Object bean) {<br \/>\n    if (bean instanceof Aware) {<br \/>\n        if (bean instanceof BeanNameAware) {<br \/>\n            ((BeanNameAware) bean).setBeanName(beanName);<br \/>\n        }<br \/>\n        if (bean instanceof BeanClassLoaderAware) {<br \/>\n            ((BeanClassLoaderAware) bean).setBeanClassLoader(getBeanClassLoader());<br \/>\n        }<br \/>\n        if (bean instanceof BeanFactoryAware) {<br \/>\n            ((BeanFactoryAware) bean).setBeanFactory(getBeanFactory());<br \/>\n        }<br \/>\n    }<br \/>\n}<\/p>\n<p>\u53ea\u5224\u65ad\u4e09\u4e2a Aware&#xff1f;\u7b49\u7b49\u2014\u2014\u4f60\u4e0d\u662f\u8bf4\u6709\u5341\u51e0\u4e2a Aware \u5417&#xff1f;\u786e\u5b9e\u6709&#xff1a;ApplicationContextAware\u3001EnvironmentAware\u3001ResourceLoaderAware\u3001ApplicationEventPublisherAware\u3001MessageSourceAware \u7b49\u7b49\u3002\u4f46\u90a3\u4e9b\u4e0d\u662f\u5728 initializeBean() \u91cc\u5904\u7406\u7684\u2014\u2014\u5b83\u4eec\u662f\u5728 ApplicationContextAwareProcessor&#xff08;\u4e00\u4e2a BeanPostProcessor&#xff09;\u7684 postProcessBeforeInitialization \u4e2d\u5904\u7406\u7684\u3002\u4e5f\u5c31\u662f\u8bf4&#xff0c;\u6240\u6709 ApplicationContext \u76f8\u5173\u7684 Aware \u662f\u5728\u7b2c\u516d\u6b65\u7684 applyBeanPostProcessorsBeforeInitialization \u4e2d\u6267\u884c\u7684&#xff0c;\u4e0d\u662f\u5728\u7b2c\u4e94\u6b65\u3002<\/p>\n<p>\u8fd9\u7ed9\u6211\u4eec\u7684\u6559\u8bad\u662f&#xff1a;Spring \u628a Aware \u5206\u6210\u4e86\u4e24\u7c7b\u2014\u2014\u5bb9\u5668\u6838\u5fc3 Aware&#xff08;BeanName\u3001BeanFactory \u7b49&#xff09;\u5728 invokeAwareMethods \u786c\u7f16\u7801\u5904\u7406&#xff0c;\u5e94\u7528\u4e0a\u4e0b\u6587\u7684 Aware \u8d70 BeanPostProcessor \u673a\u5236\u5904\u7406\u3002\u8fd9\u79cd\u5206\u5c42\u8bbe\u8ba1\u8bf4\u660e\u4e86 Spring \u6e90\u7801\u7684\u4e00\u4e2a\u7279\u70b9&#xff1a;\u80fd\u8d70\u6269\u5c55\u70b9\u8d70\u7684&#xff0c;\u7edd\u4e0d\u786c\u7f16\u7801\u3002<\/p>\n<p>\u987a\u4fbf\u8bf4\u4e00\u53e5&#xff0c;ApplicationContextAwareProcessor \u672c\u8eab\u5c31\u662f\u4e00\u4e2a\u5185\u7f6e\u7684 BeanPostProcessor&#xff0c;\u5b83\u5728 Spring \u5bb9\u5668\u542f\u52a8\u65f6\u7531 refresh() \u65b9\u6cd5\u4e2d\u7684 prepareBeanFactory() \u6ce8\u518c\u8fdb\u53bb\u7684\u3002\u4f60\u5728\u7b2c\u516d\u6b65\u7684 postProcessBeforeInitialization \u91cc\u80fd\u62ff\u5230 ApplicationContext&#xff0c;\u662f\u56e0\u4e3a\u8fd9\u4e2a\u5904\u7406\u5668\u5728 applyBeanPostProcessorsBeforeInitialization \u904d\u5386\u65f6\u6267\u884c\u4e86\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u5bf9\u4f60\u6765\u8bf4\u662f\u5b8c\u5168\u65e0\u611f\u7684\u2014\u2014\u4f60\u53ea\u9700\u8981\u8ba9\u4f60\u7684 Bean \u5b9e\u73b0 ApplicationContextAware \u63a5\u53e3&#xff0c;Spring \u5c31\u4f1a\u81ea\u52a8\u628a ApplicationContext \u4f20\u8fdb\u6765\u3002<\/p>\n<p>\u518d\u6765\u770b\u770b\u7b2c\u4e03\u6b65 invokeInitMethods \u5185\u90e8\u64cd\u4f5c\u7684\u987a\u5e8f&#xff1a;<\/p>\n<p>\/\/ \u521d\u59cb\u5316\u65b9\u6cd5\u8c03\u7528\u987a\u5e8f<br \/>\nprotected void invokeInitMethods(String beanName, Object bean, RootBeanDefinition mbd) {<br \/>\n    \/\/ \u5148\u8c03 InitializingBean \u63a5\u53e3<br \/>\n    if (bean instanceof InitializingBean) {<br \/>\n        ((InitializingBean) bean).afterPropertiesSet();<br \/>\n    }<br \/>\n    \/\/ \u518d\u8c03\u81ea\u5b9a\u4e49 init-method&#xff08;XML \u914d\u7f6e\u6216 &#064;Bean(initMethod&#061;&#8230;)&#xff09;<br \/>\n    if (mbd.getInitMethodName() !&#061; null) {<br \/>\n        invokeCustomInitMethod(beanName, bean, mbd);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u6ce8\u610f\u987a\u5e8f&#xff1a;afterPropertiesSet \u5728\u524d&#xff0c;\u81ea\u5b9a\u4e49 init-method \u5728\u540e\u3002\u5982\u679c\u4f60\u7684 Bean \u540c\u65f6\u5b9e\u73b0\u4e86 InitializingBean \u548c\u914d\u7f6e\u4e86 init-method&#xff0c;afterPropertiesSet \u4f1a\u5148\u6267\u884c\u3002\u8fd9\u4e2a\u987a\u5e8f\u5728\u67d0\u4e9b\u573a\u666f\u4e0b\u5f88\u91cd\u8981\u2014\u2014\u6bd4\u5982\u4f60\u9700\u8981\u5728 afterPropertiesSet \u91cc\u9a8c\u8bc1\u6240\u6709\u5fc5\u8981\u5c5e\u6027\u5df2\u6ce8\u5165&#xff0c;\u7136\u540e\u5728 init-method \u91cc\u542f\u52a8\u4e00\u4e9b\u540e\u53f0\u7ebf\u7a0b\u6216\u8ba2\u9605\u6d88\u606f\u961f\u5217\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5f88\u591a\u4eba\u5ffd\u7565\u7684\u7ec6\u8282&#xff1a;invokeCustomInitMethod \u8d70\u7684\u662f\u53cd\u5c04&#xff0c;\u800c\u4e14 Spring \u4f1a\u7f13\u5b58\u8fd9\u4e2a Method \u5bf9\u8c61&#xff0c;\u907f\u514d\u91cd\u590d\u53cd\u5c04\u5e26\u6765\u7684\u6027\u80fd\u5f00\u9500\u3002\u53e6\u5916\u5982\u679c\u4f60\u7684 init-method \u7684\u53c2\u6570\u5217\u8868\u662f () \u6216\u8005\u63a5\u6536 (String, Object[]) \u683c\u5f0f\u7684&#xff0c;Spring \u90fd\u80fd\u5904\u7406\u2014\u2014\u4f46\u5b9e\u9645\u4e0a\u5927\u90e8\u5206\u573a\u666f\u53ea\u9700\u8981\u65e0\u53c2\u65b9\u6cd5\u3002<\/p>\n<hr \/>\n<h3>\u7b2c\u4e5d\u6b65&#xff1a;AOP \u4ee3\u7406\u5c31\u662f\u5728\u8fd9\u91cc\u521b\u5efa\u7684<\/h3>\n<p>\/\/ AbstractAutoProxyCreator.java \u2014 \u5728 postProcessAfterInitialization \u4e2d\u521b\u5efa\u4ee3\u7406<br \/>\npublic Object postProcessAfterInitialization(Object bean, String beanName) {<br \/>\n    if (bean !&#061; null) {<br \/>\n        Object cacheKey &#061; getCacheKey(bean.getClass(), beanName);<br \/>\n        if (!this.earlyProxyReferences.contains(cacheKey)) {<br \/>\n            \/\/ \u5224\u65ad\u662f\u5426\u9700\u8981\u5bf9\u5f53\u524d Bean \u521b\u5efa\u4ee3\u7406<br \/>\n            return wrapIfNecessary(bean, beanName, cacheKey);<br \/>\n        }<br \/>\n    }<br \/>\n    return bean;<br \/>\n}<\/p>\n<p>wrapIfNecessary \u505a\u7684\u4e8b&#xff1a;<\/p>\n<p>1. \u83b7\u53d6\u5f53\u524d Bean \u6240\u6709\u7684 Advisor&#xff08;\u5207\u9762&#xff09;<\/p>\n<p>2. \u7528 Pointcut \u5339\u914d Bean \u7684\u65b9\u6cd5<\/p>\n<p>3. \u5982\u679c\u5339\u914d\u4e0a&#xff0c;\u901a\u8fc7 DefaultAopProxyFactory \u521b\u5efa\u4ee3\u7406<\/p>\n<p>4. \u8fd4\u56de\u4ee3\u7406\u5bf9\u8c61\u66ff\u6362\u539f\u59cb Bean<\/p>\n<p>\u8fd9\u4e2a\u66ff\u6362\u662f\u900f\u660e\u7684\u2014\u2014\u5bb9\u5668\u91cc\u7684 Bean \u5173\u8054\u5df2\u7ecf\u53d8\u6210\u4e86\u4ee3\u7406\u5bf9\u8c61&#xff0c;\u540e\u7eed\u6ce8\u5165\u5230\u5176\u4ed6 Bean \u91cc\u7684\u4e5f\u662f\u8fd9\u4e2a\u4ee3\u7406\u3002<\/p>\n<p>\u4f46\u8fd9\u91cc\u6709\u4e00\u4e2a\u5927\u5751&#xff1a;postProcessAfterInitialization \u4e0d\u53ea\u662f AOP \u5728\u7528\u3002 Spring \u5185\u90e8\u6709\u5f88\u591a\u5185\u7f6e\u7684 BeanPostProcessor&#xff1a;AutowiredAnnotationBeanPostProcessor&#xff08;\u5904\u7406 &#064;Autowired&#xff09;\u3001RequiredAnnotationBeanPostProcessor\u3001CommonAnnotationBeanPostProcessor&#xff08;\u5904\u7406 &#064;Resource\u3001&#064;PostConstruct&#xff09;\u7b49\u7b49\u3002\u6bcf\u4e2a BeanPostProcessor \u7684 order \u51b3\u5b9a\u4e86\u5b83\u4eec\u7684\u6267\u884c\u987a\u5e8f&#xff0c;\u8fd9\u76f4\u63a5\u5f71\u54cd\u4e86\u4f60\u7684 Bean \u6700\u7ec8\u88ab\u5904\u7406\u6210\u4ec0\u4e48\u6837\u3002<\/p>\n<p>\u5982\u679c\u8fd9\u4e9b\u5904\u7406\u5668\u7684\u987a\u5e8f\u9519\u4e86&#xff08;\u6216\u8005\u4f60\u81ea\u5df1\u6ce8\u518c\u7684 BeanPostProcessor \u4f18\u5148\u7ea7\u4e0d\u5bf9&#xff09;&#xff0c;\u5c31\u4f1a\u51fa\u73b0&#034;\u4e3a\u4ec0\u4e48\u6211\u7684 &#064;Autowired \u6ca1\u751f\u6548&#034;\u8fd9\u7c7b\u95ee\u9898\u3002<\/p>\n<hr \/>\n<h3>BeanPostProcessor \u548c BeanFactoryPostProcessor \u7684\u533a\u522b<\/h3>\n<p>\u8fd9\u4e2a\u4e5f\u662f\u9762\u8bd5\u9ad8\u9891\u6df7\u6dc6\u70b9\u3002<\/p>\n<p>BeanFactoryPostProcessor&#xff1a;\u5728 Bean \u5b9e\u4f8b\u5316\u4e4b\u524d\u6267\u884c&#xff0c;\u64cd\u4f5c\u7684\u662f BeanDefinition&#xff08;Bean \u7684\u5b9a\u4e49\u5143\u6570\u636e&#xff09;\u3002\u4f60\u53ef\u4ee5\u4fee\u6539 Bean \u7684 scope\u3001lazy-init \u6807\u8bb0\u3001\u5c5e\u6027\u503c\u7b49\u3002\u6267\u884c\u65f6\u673a\u5728 refresh() \u7684 invokeBeanFactoryPostProcessors() \u9636\u6bb5\u3002<\/p>\n<p>BeanPostProcessor&#xff1a;\u5728 Bean \u5b9e\u4f8b\u5316\u4e4b\u540e\u3001\u521d\u59cb\u5316\u524d\u540e\u6267\u884c&#xff0c;\u64cd\u4f5c\u7684\u662f Bean \u5b9e\u4f8b\u672c\u8eab\u3002\u4f60\u53ef\u4ee5\u5305\u88c5\u3001\u66ff\u6362\u3001\u4ee3\u7406 Bean\u3002<\/p>\n<p>\u7b80\u5355\u8bb0\u5fc6&#xff1a;\u524d\u8005\u6539\u914d\u7f6e&#xff0c;\u540e\u8005\u6539\u5bf9\u8c61\u3002<\/p>\n<p>\u8fd8\u6709\u4e00\u4e2a\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u70b9&#xff1a;BeanFactoryPostProcessor \u672c\u8eab\u4e0d\u652f\u6301 &#064;Order \u6ce8\u89e3\u6765\u6392\u5e8f\u2014\u2014\u4f60\u5fc5\u987b\u5b9e\u73b0 PriorityOrdered \u6216 Ordered \u63a5\u53e3\u6765\u63a7\u5236\u6267\u884c\u987a\u5e8f\u3002\u8fd9\u4e00\u70b9\u8ddf BeanPostProcessor \u7684\u884c\u4e3a\u4e0d\u4e00\u81f4&#xff0c;\u9762\u8bd5\u5b98\u5076\u5c14\u4f1a\u62ff\u8fd9\u4e2a\u6765\u8003\u5bdf\u5019\u9009\u4eba\u5bf9\u6e90\u7801\u7684\u719f\u6089\u7a0b\u5ea6\u3002<\/p>\n<hr \/>\n<h3>Spring \u8fd8\u63d0\u4f9b\u4e86\u54ea\u4e9b\u751f\u547d\u5468\u671f\u94a9\u5b50&#xff1f;<\/h3>\n<p><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044901-6a6ecc3d64dda.png\" \/><\/p>\n<p>\u9664\u4e86\u4e0a\u9762\u7684\u6838\u5fc3 13 \u6b65&#xff0c;\u8fd8\u6709\u51e0\u4e2a\u9762\u8bd5\u5b98\u53ef\u80fd\u4f1a\u95ee\u7684\u94a9\u5b50&#xff1a;<\/p>\n<p>&#064;PostConstruct \/ &#064;PreDestroy&#xff1a;JSR-250 \u89c4\u8303\u5b9a\u4e49\u7684\u521d\u59cb\u5316\/\u9500\u6bc1\u65b9\u6cd5&#xff0c;\u5728 CommonAnnotationBeanPostProcessor \u4e2d\u5904\u7406\u3002&#064;PostConstruct \u5728 postProcessBeforeInitialization \u4e2d\u6267\u884c&#xff08;\u5728 afterPropertiesSet \u4e4b\u524d&#xff09;&#xff0c;&#064;PreDestroy \u5728 destroy \u9636\u6bb5\u6267\u884c\u3002<\/p>\n<p>SmartInitializingSingleton&#xff1a;\u5728\u6240\u6709\u5355\u4f8b Bean \u90fd\u521d\u59cb\u5316\u5b8c\u6210\u540e\u89e6\u53d1\u3002afterSingletonsInstantiated() \u65b9\u6cd5\u5728\u6240\u6709 Bean \u521b\u5efa\u5b8c\u6bd5\u540e\u8c03\u7528\u4e00\u6b21&#xff0c;\u9002\u5408\u505a\u5168\u5c40\u540e\u7f6e\u5904\u7406\u2014\u2014\u6bd4\u5982\u542f\u52a8\u540e\u68c0\u67e5\u6240\u6709\u4f9d\u8d56\u662f\u5426\u5c31\u7eea\u3002<\/p>\n<p>Lifecycle \u63a5\u53e3&#xff1a;start() \u548c stop() \u65b9\u6cd5&#xff0c;\u4e3b\u8981\u7528\u4e8e\u7ba1\u7406\u5bb9\u5668\u751f\u547d\u5468\u671f\u5185\u7684\u542f\u52a8\u548c\u505c\u6b62\u884c\u4e3a\u3002Spring \u5bb9\u5668\u4f1a\u5728 refresh() \u7684\u6700\u540e\u8c03\u7528 startBeans()\u2014\u2014\u6240\u6709\u5b9e\u73b0\u4e86 Lifecycle \u7684 Bean \u4f1a\u6309\u4f9d\u8d56\u987a\u5e8f\u542f\u52a8\u3002\u8fd9\u5728 Spring Cloud \u6216\u6d88\u606f\u961f\u5217\u7684\u573a\u666f\u4e0b\u7279\u522b\u6709\u7528&#xff0c;\u6bd4\u5982\u786e\u4fdd\u8fde\u63a5\u6c60\u5728\u6d88\u606f\u76d1\u542c\u5668\u542f\u52a8\u4e4b\u524d\u5c31\u7eea\u3002<\/p>\n<p>SmartLifecycle&#xff1a;Lifecycle \u7684\u589e\u5f3a\u7248&#xff0c;\u591a\u4e86 getPhase() \u63a7\u5236\u542f\u52a8\u987a\u5e8f&#xff0c;\u4ee5\u53ca isAutoStartup() \u5224\u65ad\u662f\u5426\u81ea\u52a8\u542f\u52a8\u3002\u5982\u679c\u4f60\u7684\u5e94\u7528\u9700\u8981\u70ed\u52a0\u8f7d\u67d0\u4e9b\u7ec4\u4ef6&#xff0c;\u7528 SmartLifecycle \u6bd4\u7528 &#064;EventListener(ContextRefreshedEvent.class) \u66f4\u4f18\u96c5\u3002<\/p>\n<hr \/>\n<h3>&#x1f3af; \u9762\u8bd5\u5b98\u89c6\u89d2\u7684\u6807\u51c6\u56de\u7b54<\/h3>\n<p>&#034;Spring Bean \u7684\u5b8c\u6574\u751f\u547d\u5468\u671f\u5206\u4e3a 13 \u6b65&#xff1a;\u5b9e\u4f8b\u5316&#xff08;\u901a\u8fc7\u6784\u9020\u5668\u53cd\u5c04\u521b\u5efa\u5bf9\u8c61&#xff0c;\u540c\u65f6\u653e\u5165\u4e09\u7ea7\u7f13\u5b58\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56&#xff09;\u3001\u5c5e\u6027\u6ce8\u5165&#xff08;\u5904\u7406 &#064;Autowired\u3001&#064;Resource\u3001&#064;Value&#xff09;\u3001Aware \u63a5\u53e3\u8c03\u7528&#xff08;BeanName\u3001BeanClassLoader\u3001BeanFactory \u4e09\u4e2a\u786c\u7f16\u7801 &#043; \u5176\u4ed6\u901a\u8fc7 BeanPostProcessor&#xff09;\u3001BeanPostProcessor \u7684 Before \u5904\u7406\u5668&#xff08;\u6267\u884c &#064;PostConstruct&#xff09;\u3001InitializingBean \u7684 afterPropertiesSet\u3001\u81ea\u5b9a\u4e49 init-method\u3001BeanPostProcessor \u7684 After \u5904\u7406\u5668&#xff08;AOP \u4ee3\u7406\u5c31\u662f\u5728\u8fd9\u6b65\u521b\u5efa\u7684&#xff0c;AbstractAutoProxyCreator \u7684 wrapIfNecessary \u65b9\u6cd5\u5224\u65ad\u662f\u5426\u9700\u8981\u4ee3\u7406&#xff09;\u3001Bean \u5c31\u7eea\u3001\u9500\u6bc1\u9636\u6bb5&#xff08;&#064;PreDestroy\u3001DisposableBean.destroy\u3001\u81ea\u5b9a\u4e49 destroy-method&#xff09;\u3002\u6838\u5fc3\u7406\u89e3&#xff1a;BeanPostProcessor \u662f Spring \u6269\u5c55\u529f\u80fd\u7684\u57fa\u77f3\u2014\u2014\u6ca1\u6709\u5b83&#xff0c;AOP\u3001\u4e8b\u52a1\u3001&#064;Autowired \u5168\u90e8\u65e0\u6cd5\u5de5\u4f5c\u3002\u533a\u5206 BeanFactoryPostProcessor&#xff08;\u64cd\u4f5c BeanDefinition\u3001\u5728\u5b9e\u4f8b\u5316\u524d\u6267\u884c&#xff09;\u548c BeanPostProcessor&#xff08;\u64cd\u4f5c Bean \u5b9e\u4f8b\u3001\u5728\u521d\u59cb\u5316\u524d\u540e\u6267\u884c&#xff09;\u3002\u6709\u4e24\u4e2a\u5bb9\u6613\u88ab\u5ffd\u7565\u7684\u94a9\u5b50&#xff1a;SmartInitializingSingleton&#xff08;\u6240\u6709\u5355\u4f8b\u90fd\u521d\u59cb\u5316\u540e\u89e6\u53d1&#xff09;\u548c SmartLifecycle&#xff08;\u5bb9\u5668\u7ea7\u522b\u7684 start\/stop \u7ba1\u7406&#xff09;\u3002&#034;<\/p>\n<hr \/>\n<p>\u4e0b\u7bc7\u9884\u544a&#xff1a;\u9762\u8bd5\u5b98\u95ee\u7ebf\u7a0b\u6c60&#xff0c;\u5927\u90e8\u5206\u4eba\u53ea\u80cc\u4e86\u4e03\u4e2a\u53c2\u6570\u3002\u4e0b\u4e00\u7bc7\u6587\u7ae0\u804a ThreadPoolExecutor \u7684\u6838\u5fc3\u6e90\u7801\u2014\u2014\u961f\u5217\u6ee1\u4e86\u600e\u4e48\u529e\u3001\u62d2\u7edd\u7b56\u7565\u600e\u4e48\u9009\u3001\u6838\u5fc3\u7ebf\u7a0b\u6570\u5230\u5e95\u8bbe\u591a\u5c11\u5408\u9002\u3002<\/p>\n<p>&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u89e3\u6790 Spring Bean \u751f\u547d\u5468\u671f\u7684 13 \u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u4ece\u5b9e\u4f8b\u5316\u3001\u5c5e\u6027\u6ce8\u5165\u5230\u521d\u59cb\u5316\u524d\u540e\u7684 BeanPostProcessor \u94a9\u5b50\u673a\u5236\u3002\u91cd\u70b9\u63ed\u793a\u4e86 AOP \u4ee3\u7406\u5728 postProcessAfterInitialization \u9636\u6bb5\u521b\u5efa\u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u4ee5\u53ca\u4e09\u7ea7\u7f13\u5b58\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u7684\u5173\u952e\u8bbe\u8ba1\u3002\u6587\u7ae0\u8fd8\u5bf9\u6bd4\u4e86 BeanPostProcessor \u4e0e BeanFactoryPostProcessor \u7684\u533a\u522b&#xff0c;\u5e76\u4ecb\u7ecd\u4e86 P<\/p>\n","protected":false},"author":2,"featured_media":89094,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[99,101,292],"topic":[],"class_list":["post-89098","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-java","tag-spring","tag-292"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \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\/89098.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u89e3\u6790 Spring Bean \u751f\u547d\u5468\u671f\u7684 13 \u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u4ece\u5b9e\u4f8b\u5316\u3001\u5c5e\u6027\u6ce8\u5165\u5230\u521d\u59cb\u5316\u524d\u540e\u7684 BeanPostProcessor \u94a9\u5b50\u673a\u5236\u3002\u91cd\u70b9\u63ed\u793a\u4e86 AOP \u4ee3\u7406\u5728 postProcessAfterInitialization \u9636\u6bb5\u521b\u5efa\u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u4ee5\u53ca\u4e09\u7ea7\u7f13\u5b58\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u7684\u5173\u952e\u8bbe\u8ba1\u3002\u6587\u7ae0\u8fd8\u5bf9\u6bd4\u4e86 BeanPostProcessor \u4e0e BeanFactoryPostProcessor \u7684\u533a\u522b&#xff0c;\u5e76\u4ecb\u7ecd\u4e86 P\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/89098.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-02T04:49:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044900-6a6ecc3c5cced.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89098.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/89098.html\",\"name\":\"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-02T04:49:02+00:00\",\"dateModified\":\"2026-08-02T04:49:02+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/89098.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/89098.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89098.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d\"}]},{\"@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":"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \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\/89098.html","og_locale":"zh_CN","og_type":"article","og_title":"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6458\u8981&#xff1a;\u672c\u6587\u6df1\u5165\u89e3\u6790 Spring Bean \u751f\u547d\u5468\u671f\u7684 13 \u4e2a\u6838\u5fc3\u6b65\u9aa4&#xff0c;\u4ece\u5b9e\u4f8b\u5316\u3001\u5c5e\u6027\u6ce8\u5165\u5230\u521d\u59cb\u5316\u524d\u540e\u7684 BeanPostProcessor \u94a9\u5b50\u673a\u5236\u3002\u91cd\u70b9\u63ed\u793a\u4e86 AOP \u4ee3\u7406\u5728 postProcessAfterInitialization \u9636\u6bb5\u521b\u5efa\u7684\u5e95\u5c42\u539f\u7406&#xff0c;\u4ee5\u53ca\u4e09\u7ea7\u7f13\u5b58\u89e3\u51b3\u5faa\u73af\u4f9d\u8d56\u7684\u5173\u952e\u8bbe\u8ba1\u3002\u6587\u7ae0\u8fd8\u5bf9\u6bd4\u4e86 BeanPostProcessor \u4e0e BeanFactoryPostProcessor \u7684\u533a\u522b&#xff0c;\u5e76\u4ecb\u7ecd\u4e86 P","og_url":"https:\/\/www.wsisp.com\/helps\/89098.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-02T04:49:02+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260802044900-6a6ecc3c5cced.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/89098.html","url":"https:\/\/www.wsisp.com\/helps\/89098.html","name":"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-02T04:49:02+00:00","dateModified":"2026-08-02T04:49:02+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/89098.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/89098.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/89098.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"18 \u9762\u8bd5\u5b98\uff1aSpring Bean \u7684\u751f\u547d\u5468\u671f\u5230\u5e95\u6709\u591a\u957f\uff1f\u6211\u770b\u8fc7\u6e90\u7801\uff0c\u6bd4\u4f60\u60f3\u8c61\u7684\u590d\u6742\u4e09\u500d"}]},{"@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\/89098","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=89098"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89098\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/89094"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=89098"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=89098"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=89098"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=89098"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}