他是解决资源文件与javaConfig的同步问题的
当boot环境中properties值改变
SpringCloud触发
Apollo触发
需要对boot的java config进行刷新处理
因为config初始化之后不会再初始化了
用于SpringCloud Config的配置比较多
刷新配置可以
refreshScope
.refresh(
"sampleRedisConfig"
);
刷新被
RefreshScope修饰的配置类
或者使用
curl -X POST
http://localhost:7031/refresh 这种方法必须有 spring-boot-starter-actuator 这个starter才行.
来刷新配置
refresh的底层原理详见:
org.springframework.cloud.context.refresh.ContextRefresher#refresh
实际不知道啥意思
@RefreshScope 这个注解会生成代理类,如果不识别代理请不要使用
Field defaultShiroFilterChainDefinition in cc.parkhome.estate.ports.web.rest.TestController required a bean of type 'org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition' that could not be found.
最后一个问题,
@RefreshScope作用的类,不能是final类
,否则启动时会报错,类似下面这堆:
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class TestUtil
at org.springframework.
cglib
.proxy.Enhancer.generateClass(Enhancer.java:565) ~[spring-core-4.3.9.RELEASE.jar:4.3.9.RELEASE]