|
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.Collection; |
| 21 | +import java.util.Collections; |
21 | 22 | import java.util.HashMap; |
22 | 23 | import java.util.List; |
23 | 24 | import java.util.Map; |
24 | 25 | import java.util.Objects; |
| 26 | +import java.util.Set; |
| 27 | +import java.util.concurrent.ConcurrentHashMap; |
25 | 28 | import java.util.concurrent.TimeUnit; |
26 | 29 |
|
27 | 30 | import feign.Capability; |
@@ -85,6 +88,8 @@ public class FeignClientFactoryBean |
85 | 88 |
|
86 | 89 | private static final Log LOG = LogFactory.getLog(FeignClientFactoryBean.class); |
87 | 90 |
|
| 91 | + private static final Set<String> resolvedContextIds = Collections.newSetFromMap(new ConcurrentHashMap<>()); |
| 92 | + |
88 | 93 | private Class<?> type; |
89 | 94 |
|
90 | 95 | private String name; |
@@ -488,6 +493,14 @@ <T> T getTarget() { |
488 | 493 | // (e.g., connection pools, threads) if not properly managed. |
489 | 494 | Client client = getOptional(feignClientFactory, Client.class); |
490 | 495 | if (client != null) { |
| 496 | + if (!resolvedContextIds.add(contextId)) { |
| 497 | + if (LOG.isWarnEnabled()) { |
| 498 | + LOG.warn("FeignClient with contextId '" + contextId |
| 499 | + + "' is being initialized more than once. " |
| 500 | + + "Ensure the Client bean is Singleton scoped " |
| 501 | + + "to avoid connection pool exhaustion."); |
| 502 | + } |
| 503 | + } |
491 | 504 | if (client instanceof FeignBlockingLoadBalancerClient) { |
492 | 505 | // not load balancing because we have a url, |
493 | 506 | // but Spring Cloud LoadBalancer is on the classpath, so unwrap |
|
0 commit comments