mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:30:28 +00:00
Polishing
This commit is contained in:
+9
-15
@@ -55,8 +55,7 @@ public class SpringConfigurator extends Configurator {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(SpringConfigurator.class);
|
||||
|
||||
private static final Map<String, Map<Class<?>, String>> cache =
|
||||
new ConcurrentHashMap<>();
|
||||
private static final Map<String, Map<Class<?>, String>> cache = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -100,24 +99,19 @@ public class SpringConfigurator extends Configurator {
|
||||
|
||||
private @Nullable String getBeanNameByType(WebApplicationContext wac, Class<?> endpointClass) {
|
||||
String wacId = wac.getId();
|
||||
Map<Class<?>, String> beanNamesByType = cache.computeIfAbsent(wacId, key -> new ConcurrentHashMap<>());
|
||||
|
||||
Map<Class<?>, String> beanNamesByType = cache.computeIfAbsent(wacId, k -> new ConcurrentHashMap<>());
|
||||
|
||||
if (!beanNamesByType.containsKey(endpointClass)) {
|
||||
String beanName = beanNamesByType.get(endpointClass);
|
||||
if (beanName == null) {
|
||||
String[] names = wac.getBeanNamesForType(endpointClass);
|
||||
if (names.length == 1) {
|
||||
beanNamesByType.put(endpointClass, names[0]);
|
||||
}
|
||||
else {
|
||||
beanNamesByType.put(endpointClass, NO_VALUE);
|
||||
if (names.length > 1) {
|
||||
throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" +
|
||||
endpointClass.getName() + "]: bean names " + Arrays.toString(names));
|
||||
}
|
||||
beanName = (names.length == 1 ? names[0] : NO_VALUE);
|
||||
beanNamesByType.put(endpointClass, beanName);
|
||||
if (names.length > 1) {
|
||||
throw new IllegalStateException("Found multiple @ServerEndpoint's of type [" +
|
||||
endpointClass.getName() + "]: bean names " + Arrays.toString(names));
|
||||
}
|
||||
}
|
||||
|
||||
String beanName = beanNamesByType.get(endpointClass);
|
||||
return (NO_VALUE.equals(beanName) ? null : beanName);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user