Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
为了较方便地实现多节点应用支持,此处commit重构了ApiConfig, 将原ApiConfig类被拆成多个类:一个接口ApiConfigInterface、一个继承了原来大部分逻辑的抽象类AbstractApiConfig,一个具体的刷新类Refresher和用于webapp中真正需要的可序列化的TokenInfo实体类。
其中ApiConfigInterface定义了提供token和jsTicket的接口,而AbstractApiConfig封装了原ApiConfig的绝大部分处理逻辑,Refresher负责具体的请求刷新,TokenInfo设计为可序列化的POJO类,封装了token和jsTicket以及对应的刷新时间;
单机版仍可继续使用ApiConfig,功能和接口不变。因新的ApiConfig仍和原ApiConfig功能相同,因其实现了接口ApiConfigInterface,具体功能借助Refresher来实现,因此可以说新ApiConfig是Refresher的wrapper,或者Refresher是ApiConfig的代理实现类。
注意:创建子类化实例时,未进行token刷新,创建完实例后须明确调用tryRefresh进行刷新获取,但创建新ApiConfig实例时,则已经调用了tryRefresh进行了刷新。
一个ApiConfigRedis参考实现如下:
可在容器启动时准备好RedisConnectionFactory和RedisTemplate,注入ApiConfigRedis中,同时ApiConfigRedis也可作为bean注入,供webapp系统使用,此commit及该Redis参考实现已在生产环境中应用。