|
16 | 16 |
|
17 | 17 | package org.springframework.web.service.registry; |
18 | 18 |
|
| 19 | +import java.util.Arrays; |
| 20 | +import java.util.Objects; |
| 21 | + |
19 | 22 | import org.jspecify.annotations.Nullable; |
20 | 23 |
|
21 | 24 | import org.springframework.beans.BeansException; |
@@ -141,7 +144,7 @@ public final void registerBeanDefinitions( |
141 | 144 | @Override |
142 | 145 | public final void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry beanRegistry) { |
143 | 146 |
|
144 | | - registerHttpServices(new DefaultGroupRegistry(), metadata); |
| 147 | + registerHttpServices(DefaultGroupSpec::new, metadata); |
145 | 148 |
|
146 | 149 | RootBeanDefinition proxyRegistryBeanDef = createOrGetRegistry(beanRegistry); |
147 | 150 |
|
@@ -261,58 +264,45 @@ interface GroupSpec { |
261 | 264 |
|
262 | 265 |
|
263 | 266 | /** |
264 | | - * Default implementation of {@link GroupRegistry}. |
| 267 | + * Default implementation of {@link GroupSpec}. |
265 | 268 | */ |
266 | | - private class DefaultGroupRegistry implements GroupRegistry { |
| 269 | + private class DefaultGroupSpec implements GroupRegistry.GroupSpec { |
267 | 270 |
|
268 | | - @Override |
269 | | - public GroupSpec forGroup(String name, HttpServiceGroup.ClientType clientType) { |
270 | | - return new DefaultGroupSpec(name, clientType); |
271 | | - } |
| 271 | + private final GroupsMetadata.Registration registration; |
272 | 272 |
|
273 | | - /** |
274 | | - * Default implementation of {@link GroupSpec}. |
275 | | - */ |
276 | | - private class DefaultGroupSpec implements GroupSpec { |
277 | | - |
278 | | - private final GroupsMetadata.Registration registration; |
| 273 | + DefaultGroupSpec(String groupName, HttpServiceGroup.ClientType clientType) { |
| 274 | + clientType = (clientType != HttpServiceGroup.ClientType.UNSPECIFIED ? clientType : defaultClientType); |
| 275 | + this.registration = groupsMetadata.getOrCreateGroup(groupName, clientType); |
| 276 | + } |
279 | 277 |
|
280 | | - public DefaultGroupSpec(String groupName, HttpServiceGroup.ClientType clientType) { |
281 | | - clientType = (clientType != HttpServiceGroup.ClientType.UNSPECIFIED ? clientType : defaultClientType); |
282 | | - this.registration = groupsMetadata.getOrCreateGroup(groupName, clientType); |
283 | | - } |
| 278 | + @Override |
| 279 | + public GroupRegistry.GroupSpec register(Class<?>... serviceTypes) { |
| 280 | + Arrays.stream(serviceTypes).map(Class::getName).forEach(this::register); |
| 281 | + return this; |
| 282 | + } |
284 | 283 |
|
285 | | - @Override |
286 | | - public GroupSpec register(Class<?>... serviceTypes) { |
287 | | - for (Class<?> serviceType : serviceTypes) { |
288 | | - this.registration.httpServiceTypeNames().add(serviceType.getName()); |
289 | | - } |
290 | | - return this; |
291 | | - } |
| 284 | + @Override |
| 285 | + public GroupRegistry.GroupSpec detectInBasePackages(Class<?>... packageClasses) { |
| 286 | + Arrays.stream(packageClasses).map(Class::getPackageName).forEach(this::detectInBasePackage); |
| 287 | + return this; |
| 288 | + } |
292 | 289 |
|
293 | | - @Override |
294 | | - public GroupSpec detectInBasePackages(Class<?>... packageClasses) { |
295 | | - for (Class<?> packageClass : packageClasses) { |
296 | | - detect(packageClass.getPackageName()); |
297 | | - } |
298 | | - return this; |
299 | | - } |
| 290 | + @Override |
| 291 | + public GroupRegistry.GroupSpec detectInBasePackages(String... packageNames) { |
| 292 | + Arrays.stream(packageNames).forEach(this::detectInBasePackage); |
| 293 | + return this; |
| 294 | + } |
300 | 295 |
|
301 | | - @Override |
302 | | - public GroupSpec detectInBasePackages(String... packageNames) { |
303 | | - for (String packageName : packageNames) { |
304 | | - detect(packageName); |
305 | | - } |
306 | | - return this; |
307 | | - } |
| 296 | + private void detectInBasePackage(String packageName) { |
| 297 | + getScanner().findCandidateComponents(packageName) |
| 298 | + .stream() |
| 299 | + .map(BeanDefinition::getBeanClassName) |
| 300 | + .filter(Objects::nonNull) |
| 301 | + .forEach(this::register); |
| 302 | + } |
308 | 303 |
|
309 | | - private void detect(String packageName) { |
310 | | - for (BeanDefinition definition : getScanner().findCandidateComponents(packageName)) { |
311 | | - if (definition.getBeanClassName() != null) { |
312 | | - this.registration.httpServiceTypeNames().add(definition.getBeanClassName()); |
313 | | - } |
314 | | - } |
315 | | - } |
| 304 | + private void register(String httpServiceTypeName) { |
| 305 | + this.registration.httpServiceTypeNames().add(httpServiceTypeName); |
316 | 306 | } |
317 | 307 | } |
318 | 308 |
|
|
0 commit comments