Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cbezmen committed Oct 11, 2021
1 parent 55ceafa commit 2ee6bd7
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
Expand Up @@ -27,6 +27,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import feign.Request;
Expand All @@ -49,6 +50,7 @@
import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
Expand All @@ -57,6 +59,7 @@
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
* @author Spencer Gibb
Expand Down Expand Up @@ -193,6 +196,12 @@ public void registerFeignClients(AnnotationMetadata metadata, BeanDefinitionRegi
AnnotationMetadata annotationMetadata = beanDefinition.getMetadata();
Assert.isTrue(annotationMetadata.isInterface(), "@FeignClient can only be specified on an interface");

Class<?> beanClass = ClassUtils.resolveClassName(
Objects.requireNonNull(beanDefinition.getBeanClassName()),
Thread.currentThread().getContextClassLoader());
Assert.isTrue(Objects.isNull(AnnotationUtils.findAnnotation(beanClass, RequestMapping.class)),
"@FeignClient can't annotated with @RequestMapping");

Map<String, Object> attributes = annotationMetadata
.getAnnotationAttributes(FeignClient.class.getCanonicalName());

Expand Down
Expand Up @@ -26,9 +26,11 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.mock.env.MockEnvironment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

/**
* @author Spencer Gibb
Expand Down Expand Up @@ -101,6 +103,20 @@ public void shouldPassSubLevelFeignClient() {
.doesNotThrowAnyException();
}

@Test
public void testChildRequestMappingAnnotation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new AnnotationConfigApplicationContext(ChildRequestMappingTestConfig.class))
.withMessage("@FeignClient can't annotated with @RequestMapping");
}

@Test
public void testRequestMappingAnnotation() {
assertThatExceptionOfType(IllegalArgumentException.class)
.isThrownBy(() -> new AnnotationConfigApplicationContext(RequestMappingTestConfig.class))
.withMessage("@FeignClient can't annotated with @RequestMapping");
}

@FeignClient(name = "fallbackTestClient", url = "http://localhost:8080/", fallback = FallbackClient.class)
protected interface FallbackClient {

Expand All @@ -118,6 +134,22 @@ protected interface FallbackFactoryClient {

}

@RequestMapping
protected interface ParentRequestMappingClient {

}

@FeignClient(name = "childRequestMappingClient")
protected interface ChildRequestMappingClient extends ParentRequestMappingClient {

}

@FeignClient(name = "requestMappingClient")
@RequestMapping
protected interface RequestMappingClient {

}

@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
@EnableFeignClients(clients = { FeignClientsRegistrarTests.FallbackClient.class })
Expand All @@ -138,4 +170,18 @@ protected static class TopLevelSubLevelTestConfig {

}

@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
@EnableFeignClients(clients = { FeignClientsRegistrarTests.ChildRequestMappingClient.class })
protected static class ChildRequestMappingTestConfig {

}

@Configuration(proxyBeanMethods = false)
@EnableAutoConfiguration
@EnableFeignClients(clients = { FeignClientsRegistrarTests.RequestMappingClient.class })
protected static class RequestMappingTestConfig {

}

}

0 comments on commit 2ee6bd7

Please sign in to comment.