Skip to content

Commit 7012add

Browse files
committed
Make AbstractHttpServiceRegistrar.findHttpServices(...) protected
Make the `AbstractHttpServiceRegistrar.findHttpServices(...)` a protected method so that subclasses can use it to find bean definitions. The method was made `private` in commit 736383e, but is still useful even with the removal of `@HttpClientService`. See gh-35447
1 parent 1107a43 commit 7012add

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private Object getProxyInstance(String groupName, String httpServiceType) {
211211
* @param basePackage the names of packages to look under
212212
* @return match bean definitions
213213
*/
214-
private Stream<BeanDefinition> findHttpServices(String basePackage) {
214+
protected final Stream<BeanDefinition> findHttpServices(String basePackage) {
215215
if (this.scanner == null) {
216216
Assert.state(this.environment != null, "Environment has not been set");
217217
Assert.state(this.resourceLoader != null, "ResourceLoader has not been set");

spring-web/src/test/java/org/springframework/web/service/registry/HttpServiceRegistrarTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,15 @@
2424

2525
import org.junit.jupiter.api.Test;
2626

27+
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
2728
import org.springframework.beans.factory.config.BeanDefinition;
2829
import org.springframework.beans.factory.config.ConstructorArgumentValues;
2930
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;
3031
import org.springframework.core.env.StandardEnvironment;
32+
import org.springframework.core.io.DefaultResourceLoader;
3133
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
3234
import org.springframework.core.type.AnnotationMetadata;
35+
import org.springframework.util.ClassUtils;
3336
import org.springframework.web.service.registry.HttpServiceGroup.ClientType;
3437
import org.springframework.web.service.registry.echo.EchoA;
3538
import org.springframework.web.service.registry.echo.EchoB;
@@ -123,6 +126,18 @@ void noRegistrations() {
123126
assertBeanDefinitionCount(0);
124127
}
125128

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+
126141

127142
@SuppressWarnings("unchecked")
128143
private void doRegister(Consumer<AbstractHttpServiceRegistrar.GroupRegistry>... registrars) {
@@ -192,6 +207,21 @@ protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata m
192207
}
193208
}
194209

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+
195225
private record TestGroup(String name, Set<Class<?>> httpServiceTypes, ClientType clientType)
196226
implements HttpServiceGroup {
197227

0 commit comments

Comments
 (0)