mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-22 22:19:03 +00:00
Remove HttpServiceClient annotation
Closes gh-35431
This commit is contained in:
-62
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.service.registry;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
|
||||
/**
|
||||
* Base class for an HTTP Service registrar that detects
|
||||
* {@link HttpServiceClient @HttpServiceClient} annotated interfaces and
|
||||
* registers them.
|
||||
*
|
||||
* <p>Subclasses need to implement
|
||||
* {@link #registerHttpServices(GroupRegistry, AnnotationMetadata)} and invoke
|
||||
* {@link #findAndRegisterHttpServiceClients(GroupRegistry, List)} with the
|
||||
* list of base packages to scan.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 7.0
|
||||
*/
|
||||
public abstract class AbstractClientHttpServiceRegistrar extends AbstractHttpServiceRegistrar {
|
||||
|
||||
/**
|
||||
* Find all HTTP Services under the given base packages that also have an
|
||||
* {@link HttpServiceClient @HttpServiceClient} annotation, and register them
|
||||
* in the group specified on the annotation.
|
||||
* @param registry the registry from {@link #registerHttpServices(GroupRegistry, AnnotationMetadata)}
|
||||
* @param basePackages the base packages to scan
|
||||
*/
|
||||
protected void findAndRegisterHttpServiceClients(GroupRegistry registry, List<String> basePackages) {
|
||||
basePackages.stream()
|
||||
.flatMap(this::findHttpServices)
|
||||
.filter(definition -> definition instanceof AnnotatedBeanDefinition)
|
||||
.map(definition -> (AnnotatedBeanDefinition) definition)
|
||||
.filter(definition -> definition.getMetadata().hasAnnotation(HttpServiceClient.class.getName()))
|
||||
.filter(definition -> definition.getBeanClassName() != null)
|
||||
.forEach(definition -> {
|
||||
MergedAnnotations annotations = definition.getMetadata().getAnnotations();
|
||||
String group = annotations.get(HttpServiceClient.class).getString("group");
|
||||
registry.forGroup(group).registerTypeNames(definition.getBeanClassName());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+1
-12
@@ -211,7 +211,7 @@ public abstract class AbstractHttpServiceRegistrar implements
|
||||
* @param basePackage the names of packages to look under
|
||||
* @return match bean definitions
|
||||
*/
|
||||
protected Stream<BeanDefinition> findHttpServices(String basePackage) {
|
||||
private Stream<BeanDefinition> findHttpServices(String basePackage) {
|
||||
if (this.scanner == null) {
|
||||
Assert.state(this.environment != null, "Environment has not been set");
|
||||
Assert.state(this.resourceLoader != null, "ResourceLoader has not been set");
|
||||
@@ -267,9 +267,6 @@ public abstract class AbstractHttpServiceRegistrar implements
|
||||
/**
|
||||
* Detect HTTP Service types in the given packages, looking for
|
||||
* interfaces with type or method {@link HttpExchange} annotations.
|
||||
* <p>The performed scan, however, filters out any interfaces
|
||||
* annotated with {@link HttpServiceClient} that are instead supported
|
||||
* by {@link AbstractClientHttpServiceRegistrar}.
|
||||
*/
|
||||
GroupSpec detectInBasePackages(Class<?>... packageClasses);
|
||||
|
||||
@@ -326,19 +323,11 @@ public abstract class AbstractHttpServiceRegistrar implements
|
||||
|
||||
private void detectInBasePackage(String packageName) {
|
||||
findHttpServices(packageName)
|
||||
.filter(DefaultGroupSpec::isNotHttpServiceClientAnnotated)
|
||||
.map(BeanDefinition::getBeanClassName)
|
||||
.filter(Objects::nonNull)
|
||||
.forEach(this::registerServiceTypeName);
|
||||
}
|
||||
|
||||
private static boolean isNotHttpServiceClientAnnotated(BeanDefinition defintion) {
|
||||
if (defintion instanceof AnnotatedBeanDefinition abd) {
|
||||
return !abd.getMetadata().hasAnnotation(HttpServiceClient.class.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void registerServiceTypeName(String httpServiceTypeName) {
|
||||
this.registration.httpServiceTypeNames().add(httpServiceTypeName);
|
||||
}
|
||||
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.service.registry;
|
||||
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Annotation to mark an HTTP Service interface as a candidate client proxy creation.
|
||||
* Supported through the import of an {@link AbstractClientHttpServiceRegistrar}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 7.0
|
||||
* @see AbstractClientHttpServiceRegistrar
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface HttpServiceClient {
|
||||
|
||||
/**
|
||||
* An alias for {@link #group()}.
|
||||
*/
|
||||
@AliasFor("group")
|
||||
String value() default HttpServiceGroup.DEFAULT_GROUP_NAME;
|
||||
|
||||
/**
|
||||
* The name of the HTTP Service group for this client.
|
||||
* <p>By default, this is {@link HttpServiceGroup#DEFAULT_GROUP_NAME}.
|
||||
*/
|
||||
@AliasFor("value")
|
||||
String group() default HttpServiceGroup.DEFAULT_GROUP_NAME;
|
||||
|
||||
}
|
||||
-3
@@ -78,9 +78,6 @@ public @interface ImportHttpServices {
|
||||
/**
|
||||
* Detect HTTP Services in the packages of the specified classes, looking
|
||||
* for interfaces with type or method {@link HttpExchange} annotations.
|
||||
* <p>The performed scan, however, filters out interfaces annotated with
|
||||
* {@link HttpServiceClient} that are instead supported by
|
||||
* {@link AbstractClientHttpServiceRegistrar}.
|
||||
*/
|
||||
Class<?>[] basePackageClasses() default {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user