Polishing

This commit is contained in:
Juergen Hoeller
2025-12-04 00:12:31 +01:00
parent 667851c0fa
commit 07c0213f20
21 changed files with 35 additions and 50 deletions
@@ -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);
}