We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Describe the bug 如果依赖中有spring-retry则会无法正常初始化@LoadBalanced的RestTemplate,解决办法如下: @bean public RestTemplateCustomizer restTemplateCustomizer( @Autowired(required = false) RetryLoadBalancerInterceptor retryLoadBalancerInterceptor, @Autowired(required = false) LoadBalancerInterceptor loadBalancerInterceptor) { return restTemplate -> { List list = new ArrayList<>(restTemplate.getInterceptors()); // LoadBalancerInterceptor must invoke before EnhancedRestTemplateInterceptor if (retryLoadBalancerInterceptor != null || loadBalancerInterceptor != null) { int addIndex = list.size(); for (int i = 0; i < list.size(); i++) { if (list.get(i) instanceof EnhancedRestTemplateInterceptor) { addIndex = i; } } list.add( addIndex, retryLoadBalancerInterceptor != null ? retryLoadBalancerInterceptor : loadBalancerInterceptor); } restTemplate.setInterceptors(list); }; }
To Reproduce Steps to reproduce the behavior.
Expected behavior A clear and concise description of what you expected to happen.
Environment
Additional context Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
SkyeBeFreeman
Successfully merging a pull request may close this issue.
Describe the bug
如果依赖中有spring-retry则会无法正常初始化@LoadBalanced的RestTemplate,解决办法如下:
@bean
public RestTemplateCustomizer restTemplateCustomizer(
@Autowired(required = false) RetryLoadBalancerInterceptor retryLoadBalancerInterceptor,
@Autowired(required = false) LoadBalancerInterceptor loadBalancerInterceptor) {
return restTemplate -> {
List list = new ArrayList<>(restTemplate.getInterceptors());
// LoadBalancerInterceptor must invoke before EnhancedRestTemplateInterceptor
if (retryLoadBalancerInterceptor != null || loadBalancerInterceptor != null) {
int addIndex = list.size();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof EnhancedRestTemplateInterceptor) {
addIndex = i;
}
}
list.add(
addIndex,
retryLoadBalancerInterceptor != null
? retryLoadBalancerInterceptor
: loadBalancerInterceptor);
}
restTemplate.setInterceptors(list);
};
}
To Reproduce
Steps to reproduce the behavior.
Expected behavior
A clear and concise description of what you expected to happen.
Environment
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: