Why use reflect to access RedisProperties method? #4838
-
Above is the code in the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The answer comes from chatGPT The reason why reflection is used in RedissonAutoConfiguration to access the RedisProperties method instead of accessing it directly is because RedisProperties is an optional dependency in Redisson Spring Boot starter. If RedisProperties is not present on the classpath, attempting to access it directly would result in a ClassNotFoundException. To avoid this issue, reflection is used to check whether RedisProperties is present, and only access it through reflection if it is available. Here's the relevant code from RedissonAutoConfiguration: ` ` As you can see, ClassUtils.isPresent() is used to check if RedisProperties is present, and then ReflectionUtils.invokeMethod() is used to invoke the relevant getter methods on the RedisProperties object. This approach allows the RedissonAutoConfiguration to gracefully handle the absence of RedisProperties on the classpath. |
Beta Was this translation helpful? Give feedback.
The answer comes from chatGPT
The reason why reflection is used in RedissonAutoConfiguration to access the RedisProperties method instead of accessing it directly is because RedisProperties is an optional dependency in Redisson Spring Boot starter.
If RedisProperties is not present on the classpath, attempting to access it directly would result in a ClassNotFoundException. To avoid this issue, reflection is used to check whether RedisProperties is present, and only access it through reflection if it is available.
Here's the relevant code from RedissonAutoConfiguration:
`
private void configureSingleServerConfig(SingleServerConfig singleServerConfig, RedisProperties properties) throws Exce…