Commit 5fc76aaa by Dave Syer

Fix javadocs in @FeignClient

The descriptions of name/serviceId/value and url were out of date (name is mandatory now and can be mixed with url).
parent 24579f67
...@@ -38,21 +38,20 @@ import org.springframework.core.annotation.AliasFor; ...@@ -38,21 +38,20 @@ import org.springframework.core.annotation.AliasFor;
public @interface FeignClient { public @interface FeignClient {
/** /**
* The serviceId with optional protocol prefix. Synonym for {@link #serviceId() * The name of the service with optional protocol prefix. Synonym for {@link #name()
* serviceId}. Either serviceId or url must be specified but not both. Can be * name}. A name must be specified for all clients, whether or not a url is provided.
* specified as property key, eg: ${propertyKey}. * Can be specified as property key, eg: ${propertyKey}.
*/ */
@AliasFor("name") @AliasFor("name")
String value() default ""; String value() default "";
/** /**
* The serviceId with optional protocol prefix. Synonym for {@link #value() value}. * The service id with optional protocol prefix. Synonym for {@link #value() value}.
* Either serviceId or url must be specified but not both. Can be
* specified as property key, eg: ${propertyKey}.
* *
* @deprecated use {@link #name() name} instead * @deprecated use {@link #name() name} instead
*/ */
@Deprecated @Deprecated
@AliasFor("value")
String serviceId() default ""; String serviceId() default "";
@AliasFor("value") @AliasFor("value")
......
...@@ -181,15 +181,21 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar, ...@@ -181,15 +181,21 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
String alias = name + "FeignClient"; String alias = name + "FeignClient";
AbstractBeanDefinition beanDefinition = definition.getBeanDefinition(); AbstractBeanDefinition beanDefinition = definition.getBeanDefinition();
beanDefinition.setPrimary(true); beanDefinition.setPrimary(true);
BeanDefinitionHolder holder = new BeanDefinitionHolder( BeanDefinitionHolder holder = new BeanDefinitionHolder(beanDefinition, className,
beanDefinition, className, new String[]{alias}); new String[] { alias });
BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry); BeanDefinitionReaderUtils.registerBeanDefinition(holder, registry);
} }
private void validate(Map<String, Object> attributes) { private void validate(Map<String, Object> attributes) {
if (StringUtils.hasText((String) attributes.get("value"))) { if (StringUtils.hasText((String) attributes.get("value"))) {
Assert.isTrue(!StringUtils.hasText((String) attributes.get("name")),
"Either name or value can be specified, but not both");
Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")), Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")),
"Either serviceId or value can be specified, but not both"); "Either name (serviceId) or value can be specified, but not both");
}
if (StringUtils.hasText((String) attributes.get("name"))) {
Assert.isTrue(!StringUtils.hasText((String) attributes.get("serviceId")),
"Either name or serviceId can be specified, but not both");
} }
} }
......
...@@ -34,10 +34,10 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -34,10 +34,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
import com.netflix.client.config.CommonClientConfigKey; import com.netflix.client.config.CommonClientConfigKey;
import com.netflix.client.config.IClientConfig; import com.netflix.client.config.IClientConfig;
import feign.Request;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import feign.Request;
/** /**
* @author Spencer Gibb * @author Spencer Gibb
*/ */
...@@ -45,7 +45,7 @@ import static org.junit.Assert.assertEquals; ...@@ -45,7 +45,7 @@ import static org.junit.Assert.assertEquals;
@SpringApplicationConfiguration(classes = LoadBalancerFeignClientOverrideTests.TestConfiguration.class) @SpringApplicationConfiguration(classes = LoadBalancerFeignClientOverrideTests.TestConfiguration.class)
@WebIntegrationTest(randomPort = true, value = { @WebIntegrationTest(randomPort = true, value = {
"spring.application.name=loadBalancerFeignClientTests", "spring.application.name=loadBalancerFeignClientTests",
"feign.httpclient.enabled=false", "feign.okhttp.enabled=false"}) "feign.httpclient.enabled=false", "feign.okhttp.enabled=false" })
@DirtiesContext @DirtiesContext
public class LoadBalancerFeignClientOverrideTests { public class LoadBalancerFeignClientOverrideTests {
...@@ -55,27 +55,34 @@ public class LoadBalancerFeignClientOverrideTests { ...@@ -55,27 +55,34 @@ public class LoadBalancerFeignClientOverrideTests {
@Test @Test
public void overrideRequestOptions() { public void overrideRequestOptions() {
// specific ribbon 'bar' configuration via spring bean // specific ribbon 'bar' configuration via spring bean
Request.Options barOptions = this.context.getInstance("bar", Request.Options.class); Request.Options barOptions = this.context.getInstance("bar",
Request.Options.class);
assertEquals(1, barOptions.connectTimeoutMillis()); assertEquals(1, barOptions.connectTimeoutMillis());
assertEquals(2, barOptions.readTimeoutMillis()); assertEquals(2, barOptions.readTimeoutMillis());
assertOptions(barOptions, "bar", 1, 2); assertOptions(barOptions, "bar", 1, 2);
// specific ribbon 'foo' configuration // specific ribbon 'foo' configuration via application.yml
Request.Options fooOptions = this.context.getInstance("foo", Request.Options.class); Request.Options fooOptions = this.context.getInstance("foo",
Request.Options.class);
assertEquals(LoadBalancerFeignClient.DEFAULT_OPTIONS, fooOptions); assertEquals(LoadBalancerFeignClient.DEFAULT_OPTIONS, fooOptions);
assertOptions(fooOptions, "foo", 7, 17); assertOptions(fooOptions, "foo", 7, 17);
// generic ribbon default configuration // generic ribbon default configuration
Request.Options bazOptions = this.context.getInstance("baz", Request.Options.class); Request.Options bazOptions = this.context.getInstance("baz",
assertEquals(LoadBalancerFeignClient.DEFAULT_OPTIONS, fooOptions); Request.Options.class);
assertEquals(LoadBalancerFeignClient.DEFAULT_OPTIONS, bazOptions);
assertOptions(bazOptions, "baz", 3001, 60001); assertOptions(bazOptions, "baz", 3001, 60001);
} }
void assertOptions(Request.Options options, String name, int expectedConnect, int expectedRead) { void assertOptions(Request.Options options, String name, int expectedConnect,
LoadBalancerFeignClient client = this.context.getInstance(name, LoadBalancerFeignClient.class); int expectedRead) {
LoadBalancerFeignClient client = this.context.getInstance(name,
LoadBalancerFeignClient.class);
IClientConfig config = client.getClientConfig(options, name); IClientConfig config = client.getClientConfig(options, name);
assertEquals("connect was wrong for "+name, expectedConnect, config.get(CommonClientConfigKey.ConnectTimeout, -1).intValue()); assertEquals("connect was wrong for " + name, expectedConnect,
assertEquals("read was wrong for "+name, expectedRead, config.get(CommonClientConfigKey.ReadTimeout, -1).intValue()); config.get(CommonClientConfigKey.ConnectTimeout, -1).intValue());
assertEquals("read was wrong for " + name, expectedRead,
config.get(CommonClientConfigKey.ReadTimeout, -1).intValue());
} }
@Configuration @Configuration
...@@ -107,10 +114,9 @@ public class LoadBalancerFeignClientOverrideTests { ...@@ -107,10 +114,9 @@ public class LoadBalancerFeignClientOverrideTests {
} }
} }
@FeignClient(value = "baz") @FeignClient("baz")
interface BazClient { interface BazClient {
@RequestMapping("/") @RequestMapping("/")
String get(); String get();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment