-
Notifications
You must be signed in to change notification settings - Fork 704
New issue
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
Q. Is there any reason why does LoadBalancerCacheManager Bean excluded from autowire candidates? #1203
Comments
I'm not sure what you mean by it being excluded from Autowire Candidates. The caching should work out of the box. If you're experiencing any issues with it, please provide a minimal, complete, verifiable example that reproduces the issue. |
In @Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ Caffeine.class, CaffeineCacheManager.class })
protected static class CaffeineLoadBalancerCacheManagerConfiguration {
// Here
@Bean(autowireCandidate = false)
@ConditionalOnMissingBean
LoadBalancerCacheManager caffeineLoadBalancerCacheManager(LoadBalancerCacheProperties cacheProperties) {
return new CaffeineBasedLoadBalancerCacheManager(cacheProperties);
}
}
@Configuration(proxyBeanMethods = false)
@Conditional(OnCaffeineCacheMissingCondition.class)
@ConditionalOnClass(ConcurrentMapWithTimedEviction.class)
protected static class DefaultLoadBalancerCacheManagerConfiguration {
// Here
@Bean(autowireCandidate = false)
@ConditionalOnMissingBean
LoadBalancerCacheManager defaultLoadBalancerCacheManager(LoadBalancerCacheProperties cacheProperties) {
return new DefaultLoadBalancerCacheManager(cacheProperties);
}
} Because of this configuration, the newly registered Bean cannot be injected with @Bean
@ConditionalOnProperty(value = "spring.cloud.loadbalancer.configurations", havingValue = "zone-failover-awareness")
// LoadBalancerCacheManager cannot be injected
LoadBalancerCacheDataManager zoneFailoverAwarenessLoadBalancerCacheManager(LoadBalancerCacheManager cacheManager) {
return new ZoneFailoverAwarenessLoadBalancerCacheDataManager(cacheManager);
} If I include beans excluded from the autowire candidates again, the existing tests below will fail. Lines 130 to 171 in e4bd5b3
|
These tests exactly show why this is done - so that the LoadBalancerCache does not override cache managers configured by users or taken up from other autoconfigurations. |
Hi, I'm planning to implement a new feature so that LoadBalancer can switch to another zone if all instances within a particular zone fail to respond.
For acheiving this, the new ServiceInstanceListSupplier needs cache, which is why I wanted to inject
LoadBalancerCacheManager
.I checked that the Bean is currently excluded from Autowire Candidates, and I wonder if there is a reason why it was written like this.
I wonder if it is okay to exclude that option to achieve what I intend, or if not, what other alternatives can be used.
The text was updated successfully, but these errors were encountered: