Exclude HttpServiceClient from GroupRegistry scan

The detect methods in the GroupRegistry that find all interfaces
with HttpExchange annotations now exclude HttpServiceClient
interfaces that are instead supported by a dedicated registrar.

This ensures there is no overlap between the HttpServiceClient
registrar scan and the ImportHttpServices registrar scan or
the scan of any other custom registrar.

See gh-35244
This commit is contained in:
rstoyanchev
2025-07-31 05:01:34 +01:00
parent 09917fad7b
commit 0fc9e4ec1c
6 changed files with 37 additions and 16 deletions
@@ -25,9 +25,9 @@ import org.junit.jupiter.api.Test;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.web.service.registry.client.DefaultClient;
import org.springframework.web.service.registry.client.EchoClientA;
import org.springframework.web.service.registry.client.EchoClientB;
import org.springframework.web.service.registry.basic.BasicClient;
import org.springframework.web.service.registry.echo.EchoClientA;
import org.springframework.web.service.registry.echo.EchoClientB;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@@ -43,21 +43,24 @@ public class HttpServiceClientRegistrarSupportTests {
@Test
void register() {
List<String> basePackages = List.of(
BasicClient.class.getPackageName(), EchoClientA.class.getPackageName());
HttpServiceClientRegistrarSupport registrar = new HttpServiceClientRegistrarSupport() {
@Override
protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) {
findAndRegisterHttpServiceClients(groupRegistry, List.of(getClass().getPackage().getName() + ".client"));
findAndRegisterHttpServiceClients(groupRegistry, basePackages);
}
};
registrar.setEnvironment(new StandardEnvironment());
registrar.setResourceLoader(new PathMatchingResourcePatternResolver());
registrar.registerHttpServices(groupRegistry, mock(AnnotationMetadata.class));
assertGroups(
TestGroup.ofListing("echo", EchoClientA.class, EchoClientB.class),
TestGroup.ofListing("default", DefaultClient.class));
TestGroup.ofListing("default", BasicClient.class),
TestGroup.ofListing("echo", EchoClientA.class, EchoClientB.class));
}
private void assertGroups(TestGroup... expectedGroups) {
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.service.registry.client;
package org.springframework.web.service.registry.basic;
import org.springframework.web.bind.annotation.RequestParam;
@@ -22,7 +22,7 @@ import org.springframework.web.service.annotation.GetExchange;
import org.springframework.web.service.registry.HttpServiceClient;
@HttpServiceClient
public interface DefaultClient {
public interface BasicClient {
@GetExchange
String handle(@RequestParam String input);
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.service.registry.client;
package org.springframework.web.service.registry.echo;
import org.springframework.web.bind.annotation.RequestParam;
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.web.service.registry.client;
package org.springframework.web.service.registry.echo;
import org.springframework.web.bind.annotation.RequestParam;