Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
spring-cloud-netflix
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openSource
spring-cloud-netflix
Commits
08f7076f
Commit
08f7076f
authored
Mar 16, 2016
by
Spencer Gibb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mark @FeignClient beans as primary.
When fallback beans are created, there was no longer a unique bean of the feign interface which caused autowire problems. fixes gh-899
parent
b9a6876d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
spring-cloud-netflix.adoc
docs/src/main/asciidoc/spring-cloud-netflix.adoc
+1
-1
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+7
-3
FeignClientTests.java
...framework/cloud/netflix/feign/valid/FeignClientTests.java
+16
-5
No files found.
docs/src/main/asciidoc/spring-cloud-netflix.adoc
View file @
08f7076f
...
...
@@ -789,7 +789,7 @@ In the `@FeignClient` annotation the String value ("stores" above) is
an
arbitrary
client
name
,
which
is
used
to
create
a
Ribbon
load
balancer
(
see
<<
spring
-
cloud
-
ribbon
,
below
for
details
of
Ribbon
support
>>).
You
can
also
specify
a
URL
using
the
`
url
`
attribute
(
absolute
value
or
just
a
hostname
).
(
absolute
value
or
just
a
hostname
).
The
name
of
the
bean
in
the
application
context
is
the
fully
qualified
name
of
the
interface
.
An
alias
is
also
created
which
is
the
'name'
attribute
plus
'FeignClient'
.
For
the
example
above
,
`@
Qualifier
(
"storesFeignClient"
)`
could
be
used
to
reference
the
bean
.
The
Ribbon
client
above
will
want
to
discover
the
physical
addresses
for
the
"stores"
service
.
If
your
application
is
a
Eureka
client
then
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsRegistrar.java
View file @
08f7076f
...
...
@@ -171,14 +171,18 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
.
genericBeanDefinition
(
FeignClientFactoryBean
.
class
);
validate
(
attributes
);
definition
.
addPropertyValue
(
"url"
,
getUrl
(
attributes
));
definition
.
addPropertyValue
(
"name"
,
getServiceId
(
attributes
));
String
name
=
getName
(
attributes
);
definition
.
addPropertyValue
(
"name"
,
name
);
definition
.
addPropertyValue
(
"type"
,
className
);
definition
.
addPropertyValue
(
"decode404"
,
attributes
.
get
(
"decode404"
));
definition
.
addPropertyValue
(
"fallback"
,
attributes
.
get
(
"fallback"
));
definition
.
setAutowireMode
(
AbstractBeanDefinition
.
AUTOWIRE_BY_TYPE
);
String
alias
=
name
+
"FeignClient"
;
AbstractBeanDefinition
beanDefinition
=
definition
.
getBeanDefinition
();
beanDefinition
.
setPrimary
(
true
);
BeanDefinitionHolder
holder
=
new
BeanDefinitionHolder
(
definition
.
getBeanDefinition
(),
className
);
beanDefinition
,
className
,
new
String
[]{
alias
}
);
BeanDefinitionReaderUtils
.
registerBeanDefinition
(
holder
,
registry
);
}
...
...
@@ -189,7 +193,7 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
}
}
private
String
get
ServiceId
(
Map
<
String
,
Object
>
attributes
)
{
private
String
get
Name
(
Map
<
String
,
Object
>
attributes
)
{
String
name
=
(
String
)
attributes
.
get
(
"serviceId"
);
if
(!
StringUtils
.
hasText
(
name
))
{
name
=
(
String
)
attributes
.
get
(
"name"
);
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/FeignClientTests.java
View file @
08f7076f
...
...
@@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Qualifier
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
...
...
@@ -115,6 +116,10 @@ public class FeignClientTests {
@Autowired
HystrixClient
hystrixClient
;
@Autowired
@Qualifier
(
"localapp3FeignClient"
)
HystrixClient
namedHystrixClient
;
protected
enum
Arg
{
A
,
B
;
...
...
@@ -270,6 +275,12 @@ public class FeignClientTests {
})
protected
static
class
Application
{
// needs to be in parent context to test multiple HystrixClient beans
@Bean
public
HystrixClientFallback
hystrixClientFallback
()
{
return
new
HystrixClientFallback
();
}
@Bean
FeignFormatterRegistrar
feignFormatterRegistrar
()
{
return
new
FeignFormatterRegistrar
()
{
...
...
@@ -543,6 +554,11 @@ public class FeignClientTests {
assertEquals
(
"message was wrong"
,
"fallbackfuture"
,
hello
.
getMessage
());
}
@Test
public
void
namedFeignClientWorks
()
{
assertNotNull
(
"namedHystrixClient was null"
,
this
.
namedHystrixClient
);
}
@Data
@AllArgsConstructor
@NoArgsConstructor
...
...
@@ -556,11 +572,6 @@ public class FeignClientTests {
Logger
.
Level
feignLoggerLevel
()
{
return
Logger
.
Level
.
FULL
;
}
@Bean
public
HystrixClientFallback
hystrixClientFallback
()
{
return
new
HystrixClientFallback
();
}
}
// Load balancer with fixed server list for "local" pointing to localhost
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment