读取配置中心更新后数据抛出异常

来源:互联网 发布:java string.replace 编辑:程序博客网 时间:2024/06/15 03:16
在*****ScheduleImpl中定义属性,如下所示   备注: @AutoUpdate为公司内部注解
@Value("${batch.size:300}")@AutoUpdate@Getter@Setterprivate Integer batchSize;
当配置中心修改值后,程序抛出异常,如下
2017-09-29 16:25:16.012 [TxId :  , SpanId : ] [ERROR] | clc-ums-config-manager-_-dev-_-default-thread-1 |  | c.z.c.c.a.r.DefaultConfigUpdater:103 | Invalid property 'batchSize' of bean class [com.sun.proxy.$Proxy221]: Bean property 'batchSize' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?org.springframework.beans.NotWritablePropertyException: Invalid property 'batchSize' of bean class [com.sun.proxy.$Proxy221]: Bean property 'batchSize' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?    at org.springframework.beans.BeanWrapperImpl.createNotWritablePropertyException(BeanWrapperImpl.java:243)    at org.springframework.beans.AbstractNestablePropertyAccessor.processLocalProperty(AbstractNestablePropertyAccessor.java:437)    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:292)    at org.springframework.beans.AbstractNestablePropertyAccessor.setPropertyValue(AbstractNestablePropertyAccessor.java:260)    at com.zhubajie.configcenter.client.spring.SpringAutoUpdateListener.updateAttrs(SpringAutoUpdateListener.java:70)    at com.zhubajie.configcenter.client.spring.SpringAutoUpdateListener.onChanged(SpringAutoUpdateListener.java:56)    at com.zhubajie.configcenter.client.api.runtime.DefaultConfigUpdater.triggerListener(DefaultConfigUpdater.java:309)    at com.zhubajie.configcenter.client.api.runtime.DefaultConfigUpdater.checkLocalConfigUpdate(DefaultConfigUpdater.java:171)    at com.zhubajie.configcenter.client.api.runtime.DefaultConfigUpdater$2.run(DefaultConfigUpdater.java:101)    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)    at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)    at java.lang.Thread.run(Thread.java:745)
是因为公司配置中心不支持Dubbo提供者中直接通过属性方式注入,那么我们提供公共配置中心key读取Service即可,如下
import com.zhubajie.***;import lombok.Getter;import lombok.Setter;import org.springframework.beans.factory.annotation.Value;import org.springframework.stereotype.Component;@Setter@Getter@Componentpublic AutoService {    @AutoUpdate    private Integer batchSize;}
原创粉丝点击