Skip to content

在private方法上定义@Value,配置热更失败 #108

@InscienceMan

Description

@InscienceMan

描述bug
我在一个private的set方法上定义了@value注解,第一次配置能够正常注入,后续在Apollo上修改配置,更新失败

复现

通过如下步骤可以复现:

  1. 在需要监听配置Bean 添加成员变量 并用@Autowired注入,该类定义为FeignClient的interface
  2. 启动服务时,Feign启动会触发子容器刷新事件,被ClearCachesApplicationListener监听到,清空ReflectionUtils缓存
    3.Apollo获取@value的方法时,缓存为空,重新生成缓存,private方法accessible为false

期望

简介明了地描述你希望正常情况下应该发生什么
是否在SpringValue的injectMethod方法调用前,先调用method.setAccessible(true)

截图

如果可以,附上截图来描述你的问题

Image

额外的细节和日志

  • 版本:
  • 错误日志

java.lang.IllegalAccessException: class com.ctrip.framework.apollo.spring.property.SpringValue cannot access a member of class A with modifiers "private"
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:394) ~[na:na]
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:714) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:571) ~[na:na]
at com.ctrip.framework.apollo.spring.property.SpringValue.injectMethod(SpringValue.java:80) ~[]
at com.ctrip.framework.apollo.spring.property.SpringValue.update(SpringValue.java:59) ~[]
at com.ctrip.framework.apollo.spring.property.AutoUpdateConfigChangeListener.updateSpringValue(AutoUpdateConfigChangeListener.java:69) ~[]
at com.ctrip.framework.apollo.spring.property.AutoUpdateConfigChangeListener.onChange(AutoUpdateConfigChangeListener.java:61) ~[]

  • 配置:
  • 平台和操作系统

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions