在private方法上定义@Value,配置热更失败
stale
<!-- 这段文字不会显示在你的内容中。为了避免重复的信息,方便后续的检索,在提issue之前,请检查如下事项。如果是比较新手级别的问题,推荐到讨论区 https://github.com/apolloconfig/apollo-java/discussions 提问 -->
- [x] 我已经检查过[discussions](https://github.com/apolloconfig/apollo-java/discussions)
- [x] 我已经搜索过[issues](https://github.com/apolloconfig/apollo-java/issues)
- [x] 我已经仔细检查过[FAQ](https://www.apolloconfig.com/#/zh/faq/common-issues-in-deployment-and-development-phase)
**描述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)
**截图**
如果可以,附上截图来描述你的问题
<img width="1961" height="318" alt="Image" src="https://github.com/user-attachments/assets/c8f6b4ed-b8e3-469a-afef-13ae23bb92a9" />
### 额外的细节和日志
- 版本:
- 错误日志
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) ~[]
- 配置:
- 平台和操作系统
2 条评论