|
24 | 24 |
|
25 | 25 | import org.junit.jupiter.api.Test; |
26 | 26 |
|
| 27 | +import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; |
27 | 28 | import org.springframework.beans.factory.config.BeanDefinition; |
28 | 29 | import org.springframework.beans.factory.config.ConstructorArgumentValues; |
29 | 30 | import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry; |
30 | 31 | import org.springframework.core.env.StandardEnvironment; |
| 32 | +import org.springframework.core.io.DefaultResourceLoader; |
31 | 33 | import org.springframework.core.io.support.PathMatchingResourcePatternResolver; |
32 | 34 | import org.springframework.core.type.AnnotationMetadata; |
| 35 | +import org.springframework.util.ClassUtils; |
33 | 36 | import org.springframework.web.service.registry.HttpServiceGroup.ClientType; |
34 | 37 | import org.springframework.web.service.registry.echo.EchoA; |
35 | 38 | import org.springframework.web.service.registry.echo.EchoB; |
@@ -123,6 +126,18 @@ void noRegistrations() { |
123 | 126 | assertBeanDefinitionCount(0); |
124 | 127 | } |
125 | 128 |
|
| 129 | + @Test |
| 130 | + void registrarUsingFindHttpService() { |
| 131 | + TestRegistrarUsingFindHttpServices registrar = new TestRegistrarUsingFindHttpServices(); |
| 132 | + registrar.setEnvironment(new StandardEnvironment()); |
| 133 | + registrar.setResourceLoader(new DefaultResourceLoader()); |
| 134 | + registrar.registerBeanDefinitions(null, beanDefRegistry); |
| 135 | + |
| 136 | + assertRegistryBeanDef( |
| 137 | + new TestGroup("EchoA", EchoA.class), |
| 138 | + new TestGroup("EchoB", EchoB.class)); |
| 139 | + } |
| 140 | + |
126 | 141 |
|
127 | 142 | @SuppressWarnings("unchecked") |
128 | 143 | private void doRegister(Consumer<AbstractHttpServiceRegistrar.GroupRegistry>... registrars) { |
@@ -192,6 +207,21 @@ protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata m |
192 | 207 | } |
193 | 208 | } |
194 | 209 |
|
| 210 | + private static class TestRegistrarUsingFindHttpServices extends AbstractHttpServiceRegistrar { |
| 211 | + |
| 212 | + @Override |
| 213 | + protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { |
| 214 | + findHttpServices(EchoA.class.getPackageName()) |
| 215 | + .map(definition -> ((AnnotatedBeanDefinition) definition).getMetadata()) |
| 216 | + .forEach(metadata -> { |
| 217 | + String className = metadata.getClassName(); |
| 218 | + String shortName = ClassUtils.getShortName(className); |
| 219 | + registry.forGroup(shortName).registerTypeNames(className); |
| 220 | + }); |
| 221 | + } |
| 222 | + |
| 223 | + } |
| 224 | + |
195 | 225 | private record TestGroup(String name, Set<Class<?>> httpServiceTypes, ClientType clientType) |
196 | 226 | implements HttpServiceGroup { |
197 | 227 |
|
|
0 commit comments