Skip to content

Commit 87fa9a5

Browse files
committed
Polishing in GroupsMetadata
See gh-33992
1 parent 85bc635 commit 87fa9a5

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Diff for: spring-web/src/main/java/org/springframework/web/service/registry/AbstractHttpServiceRegistrar.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,9 @@ public final void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefin
142142

143143
mergeGroups(proxyRegistryBeanDef);
144144

145-
this.groupsMetadata.forEachRegistration(group -> group.httpServiceTypeNames().forEach(type -> {
145+
this.groupsMetadata.forEachRegistration((groupName, types) -> types.forEach(type -> {
146146
GenericBeanDefinition proxyBeanDef = new GenericBeanDefinition();
147147
proxyBeanDef.setBeanClassName(type);
148-
String groupName = group.name();
149148
String beanName = (groupName + "#" + type);
150149
proxyBeanDef.setInstanceSupplier(() -> getProxyInstance(proxyRegistryBeanName, groupName, type));
151150
if (!beanRegistry.containsBeanDefinition(beanName)) {

Diff for: spring-web/src/main/java/org/springframework/web/service/registry/GroupsMetadata.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import java.util.LinkedHashSet;
2222
import java.util.Map;
2323
import java.util.Set;
24-
import java.util.function.Consumer;
24+
import java.util.function.BiConsumer;
2525
import java.util.stream.Collectors;
2626

2727
import org.springframework.util.Assert;
@@ -54,16 +54,24 @@ public Registration getOrCreateGroup(String groupName, HttpServiceGroup.ClientTy
5454
* Merge all registrations from the given {@link GroupsMetadata} into this one.
5555
*/
5656
public void mergeWith(GroupsMetadata other) {
57-
other.forEachRegistration(registration ->
57+
other.groupMap.values().forEach(registration ->
5858
getOrCreateGroup(registration.name(), registration.clientType())
5959
.httpServiceTypeNames()
6060
.addAll(registration.httpServiceTypeNames()));
6161
}
6262

63-
public void forEachRegistration(Consumer<Registration> consumer) {
64-
this.groupMap.values().forEach(consumer);
63+
/**
64+
* Callback to apply to all registrations with access to the group name and
65+
* its HTTP service type names.
66+
*/
67+
public void forEachRegistration(BiConsumer<String, Set<String>> consumer) {
68+
this.groupMap.values().forEach(registration ->
69+
consumer.accept(registration.name(), registration.httpServiceTypeNames()));
6570
}
6671

72+
/**
73+
* Create the {@link HttpServiceGroup}s for all registrations.
74+
*/
6775
public Collection<HttpServiceGroup> groups() {
6876
return this.groupMap.values().stream().map(DefaultRegistration::toHttpServiceGroup).toList();
6977
}

0 commit comments

Comments
 (0)