RefreshScope注解做用
时间: 2023-09-04 07:06:23 浏览: 59
RefreshScope注解的作用是用于标记一个Bean,表示当配置源发生变化时,需要刷新该Bean的实例。它是Spring Cloud提供的用于实现动态刷新配置功能的注解之一。通过在需要刷新的Bean上添加@RefreshScope注解,Spring容器会对该Bean进行特殊处理,在配置源发生变化时,会重新生成该Bean的实例,并更新其中的配置值,以实现动态更新配置的效果。 RefreshScope注解的处理由RefreshScope组件来完成,RefreshScope继承自GenericScope,并实现了BeanDefinitionRegistryPostProcessor和BeanFactoryPostProcessor接口。在容器启动时,RefreshScope会先调用BeanDefinitionRegistryPostProcessor接口中的postProcessBeanDefinitionRegistry()方法,再调用BeanFactoryPostProcessor接口中的postProcessBeanFactory()方法来处理RefreshScope注解,并将需要刷新的Bean添加到RefreshScope的作用域中。 RefreshScope会获取容器中所有的Bean定义,并通过判断Bean装饰的Bean定义的作用域是否为RefreshScope来确定是否需要处理该Bean。如果是需要处理的Bean,RefreshScope会将其类设置为LockedScopedProxyFactoryBean,并将当前RefreshScope实例对象作为构造函数的参数,以实现动态刷新配置的功能。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [@RefreshScope注解处理](https://blog.csdn.net/weixin_42145727/article/details/127371032)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]