Skip to content

Commit 10e32c9

Browse files
committed
Make container annotation for ImportHttpServices nested
See gh-33992
1 parent a122dda commit 10e32c9

File tree

6 files changed

+35
-99
lines changed

6 files changed

+35
-99
lines changed

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

+6-11
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,23 @@
3232
class AnnotationHttpServiceRegistrar extends AbstractHttpServiceRegistrar {
3333

3434
@Override
35-
protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importMetadata) {
35+
protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata metadata) {
3636

37-
MergedAnnotation<?> groupsAnnot = importMetadata.getAnnotations().get(ImportHttpServiceGroups.class);
37+
MergedAnnotation<?> groupsAnnot = metadata.getAnnotations().get(ImportHttpServices.Container.class);
3838
if (groupsAnnot.isPresent()) {
39-
HttpServiceGroup.ClientType clientType = groupsAnnot.getEnum("clientType", HttpServiceGroup.ClientType.class);
4039
for (MergedAnnotation<?> annot : groupsAnnot.getAnnotationArray("value", ImportHttpServices.class)) {
41-
processImportAnnotation(annot, registry, clientType);
40+
processImportAnnotation(annot, registry);
4241
}
4342
}
4443

45-
importMetadata.getAnnotations().stream(ImportHttpServices.class).forEach(annot ->
46-
processImportAnnotation(annot, registry, HttpServiceGroup.ClientType.UNSPECIFIED));
44+
metadata.getAnnotations().stream(ImportHttpServices.class)
45+
.forEach(annot -> processImportAnnotation(annot, registry));
4746
}
4847

49-
private void processImportAnnotation(
50-
MergedAnnotation<?> annotation, GroupRegistry groupRegistry,
51-
HttpServiceGroup.ClientType containerClientType) {
48+
private void processImportAnnotation(MergedAnnotation<?> annotation, GroupRegistry groupRegistry) {
5249

5350
String groupName = annotation.getString("group");
54-
5551
HttpServiceGroup.ClientType clientType = annotation.getEnum("clientType", HttpServiceGroup.ClientType.class);
56-
clientType = (clientType != HttpServiceGroup.ClientType.UNSPECIFIED ? clientType : containerClientType);
5752

5853
groupRegistry.forGroup(groupName, clientType)
5954
.register(annotation.getClassArray("types"))

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

-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ enum ClientType {
7070
/**
7171
* Not specified, falling back on a default.
7272
* @see ImportHttpServices#clientType()
73-
* @see ImportHttpServiceGroups#clientType()
7473
* @see AbstractHttpServiceRegistrar#setDefaultClientType
7574
*/
7675
UNSPECIFIED;

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

-66
This file was deleted.

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

+17-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@
4646
* @author Olga Maciaszek-Sharma
4747
* @author Rossen Stoyanchev
4848
* @since 7.0
49-
* @see ImportHttpServiceGroups
49+
* @see Container
5050
* @see AbstractHttpServiceRegistrar
5151
*/
5252
@Retention(RetentionPolicy.RUNTIME)
5353
@Target(ElementType.TYPE)
54-
@Repeatable(ImportHttpServiceGroups.class)
54+
@Repeatable(ImportHttpServices.Container.class)
5555
@Import(AnnotationHttpServiceRegistrar.class)
5656
@Documented
5757
public @interface ImportHttpServices {
@@ -96,4 +96,19 @@
9696
*/
9797
HttpServiceGroup.ClientType clientType() default HttpServiceGroup.ClientType.UNSPECIFIED;
9898

99+
100+
/**
101+
* Container annotation that is necessary for the repeatable
102+
* {@link ImportHttpServices} annotation, but does not need to be declared
103+
* in application code.
104+
*/
105+
@Target(ElementType.TYPE)
106+
@Retention(RetentionPolicy.RUNTIME)
107+
@Documented
108+
@Import(AnnotationHttpServiceRegistrar.class)
109+
@interface Container {
110+
111+
ImportHttpServices[] value() default {};
112+
}
113+
99114
}

Diff for: spring-web/src/test/java/org/springframework/web/service/registry/AnnotationHttpServiceRegistrarTests.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void basicScan() {
6363
}
6464

6565
@Test
66-
void containerWithClientType() {
67-
doRegister(ContainerConfig.class);
66+
void clientType() {
67+
doRegister(ClientTypeConfig.class);
6868
assertGroups(
6969
StubGroup.ofListing(ECHO_GROUP, ClientType.WEB_CLIENT, EchoA.class),
7070
StubGroup.ofListing(GREETING_GROUP, ClientType.WEB_CLIENT, GreetingA.class));
@@ -97,19 +97,17 @@ private static class ListingConfig {
9797
private static class ScanConfig {
9898
}
9999

100-
@ImportHttpServiceGroups(clientType = ClientType.WEB_CLIENT, groups = {
101-
@ImportHttpServices(group = ECHO_GROUP, types = {EchoA.class}),
102-
@ImportHttpServices(group = GREETING_GROUP, types = {GreetingA.class})
103-
})
104-
private static class ContainerConfig {
100+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = ECHO_GROUP, types = {EchoA.class})
101+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = GREETING_GROUP, types = {GreetingA.class})
102+
private static class ClientTypeConfig {
105103
}
106104

107105

108106
private static class TestAnnotationHttpServiceRegistrar extends AnnotationHttpServiceRegistrar {
109107

110108
@Override
111-
public void registerHttpServices(GroupRegistry registry, AnnotationMetadata importMetadata) {
112-
super.registerHttpServices(registry, importMetadata);
109+
public void registerHttpServices(GroupRegistry registry, AnnotationMetadata metadata) {
110+
super.registerHttpServices(registry, metadata);
113111
}
114112
}
115113

Diff for: spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/WebClientProxyRegistryIntegrationTests.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@
3737
import org.springframework.web.reactive.function.client.support.greeting.GreetingB;
3838
import org.springframework.web.service.registry.AbstractHttpServiceRegistrar;
3939
import org.springframework.web.service.registry.HttpServiceGroup.ClientType;
40-
import org.springframework.web.service.registry.ImportHttpServices;
41-
import org.springframework.web.service.registry.ImportHttpServiceGroups;
4240
import org.springframework.web.service.registry.HttpServiceProxyRegistry;
41+
import org.springframework.web.service.registry.ImportHttpServices;
4342

4443
import static org.assertj.core.api.Assertions.assertThat;
4544

@@ -126,19 +125,15 @@ public WebClientHttpServiceGroupConfigurer groupConfigurer() {
126125

127126

128127
@Configuration(proxyBeanMethods = false)
129-
@ImportHttpServiceGroups(clientType = ClientType.WEB_CLIENT, groups = {
130-
@ImportHttpServices(group = "echo", types = {EchoA.class, EchoB.class}),
131-
@ImportHttpServices(group = "greeting", types = {GreetingA.class, GreetingB.class})
132-
})
128+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = "echo", types = {EchoA.class, EchoB.class})
129+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = "greeting", types = {GreetingA.class, GreetingB.class})
133130
private static class ListingConfig extends BaseEchoConfig {
134131
}
135132

136133

137134
@Configuration(proxyBeanMethods = false)
138-
@ImportHttpServiceGroups(clientType = ClientType.WEB_CLIENT, groups = {
139-
@ImportHttpServices(group = "echo", basePackageClasses = EchoA.class),
140-
@ImportHttpServices(group = "greeting", basePackageClasses = GreetingA.class)
141-
})
135+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = "echo", basePackageClasses = EchoA.class)
136+
@ImportHttpServices(clientType = ClientType.WEB_CLIENT, group = "greeting", basePackageClasses = GreetingA.class)
142137
private static class DetectConfig extends BaseEchoConfig {
143138
}
144139

0 commit comments

Comments
 (0)