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
82991a7f
Commit
82991a7f
authored
Jan 26, 2016
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make feign client bean id unique (use full classname)
Fixes gh-790
parent
3c5126c7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
181 additions
and
30 deletions
+181
-30
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+1
-11
FeignContext.java
...org/springframework/cloud/netflix/feign/FeignContext.java
+2
-3
EnableFeignClientsTests.java
...ramework/cloud/netflix/feign/EnableFeignClientsTests.java
+16
-16
FeignClientTests.java
...framework/cloud/netflix/feign/beans/FeignClientTests.java
+105
-0
TestClient.java
...springframework/cloud/netflix/feign/beans/TestClient.java
+29
-0
TestClient.java
...framework/cloud/netflix/feign/beans/extra/TestClient.java
+28
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsRegistrar.java
View file @
82991a7f
...
...
@@ -177,10 +177,8 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
definition
.
addPropertyValue
(
"fallback"
,
attributes
.
get
(
"fallback"
));
definition
.
setAutowireMode
(
AbstractBeanDefinition
.
AUTOWIRE_BY_TYPE
);
String
beanName
=
StringUtils
.
uncapitalize
(
className
.
substring
(
className
.
lastIndexOf
(
"."
)
+
1
));
BeanDefinitionHolder
holder
=
new
BeanDefinitionHolder
(
definition
.
getBeanDefinition
(),
bean
Name
);
definition
.
getBeanDefinition
(),
class
Name
);
BeanDefinitionReaderUtils
.
registerBeanDefinition
(
holder
,
registry
);
}
...
...
@@ -351,14 +349,6 @@ public class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
this
.
delegates
=
delegates
;
}
/*
* (non-Javadoc)
*
* @see
* org.springframework.core.type.filter.TypeFilter#match(org.springframework.core.
* type.classreading.MetadataReader,
* org.springframework.core.type.classreading.MetadataReaderFactory)
*/
@Override
public
boolean
match
(
MetadataReader
metadataReader
,
MetadataReaderFactory
metadataReaderFactory
)
throws
IOException
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignContext.java
View file @
82991a7f
...
...
@@ -19,9 +19,8 @@ package org.springframework.cloud.netflix.feign;
import
org.springframework.cloud.context.named.NamedContextFactory
;
/**
* A factory that creates instances of feign classes. It * creates a Spring
* ApplicationContext per client name, and extracts the beans that it
* needs from there.
* A factory that creates instances of feign classes. It creates a Spring
* ApplicationContext per client name, and extracts the beans that it needs from there.
*
* @author Spencer Gibb
* @author Dave Syer
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/EnableFeignClientsTests.java
View file @
82991a7f
...
...
@@ -16,13 +16,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
feign
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.Logger
;
import
feign.codec.Decoder
;
import
feign.codec.Encoder
;
import
feign.hystrix.HystrixFeign
;
import
feign.slf4j.Slf4jLogger
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -32,12 +25,19 @@ import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
import
org.springframework.cloud.netflix.feign.support.ResponseEntityDecoder
;
import
org.springframework.cloud.netflix.feign.support.SpringEncoder
;
import
org.springframework.cloud.netflix.feign.support.SpringMvcContract
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Import
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.Logger
;
import
feign.codec.Decoder
;
import
feign.codec.Encoder
;
import
feign.hystrix.HystrixFeign
;
import
feign.slf4j.Slf4jLogger
;
/**
* @author Spencer Gibb
*/
...
...
@@ -49,12 +49,10 @@ public class EnableFeignClientsTests {
@Autowired
private
FeignContext
feignContext
;
@Autowired
private
ApplicationContext
context
;
@Test
public
void
decoderDefaultCorrect
()
{
ResponseEntityDecoder
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Decoder
.
class
));
ResponseEntityDecoder
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Decoder
.
class
));
}
@Test
...
...
@@ -69,17 +67,19 @@ public class EnableFeignClientsTests {
@Test
public
void
contractDefaultCorrect
()
{
SpringMvcContract
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Contract
.
class
));
SpringMvcContract
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Contract
.
class
));
}
@Test
public
void
builderDefaultCorrect
()
{
HystrixFeign
.
Builder
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Feign
.
Builder
.
class
));
HystrixFeign
.
Builder
.
class
.
cast
(
this
.
feignContext
.
getInstance
(
"foo"
,
Feign
.
Builder
.
class
));
}
@Configuration
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
FeignAutoConfiguration
.
class
})
@Import
({
PropertyPlaceholderAutoConfiguration
.
class
,
ArchaiusAutoConfiguration
.
class
,
FeignAutoConfiguration
.
class
})
protected
static
class
PlainConfiguration
{
}
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/beans/FeignClientTests.java
0 → 100644
View file @
82991a7f
/*
* Copyright 2013-2015 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
*
* http://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
.
cloud
.
netflix
.
feign
.
beans
;
import
java.lang.reflect.InvocationHandler
;
import
java.lang.reflect.Proxy
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.boot.test.WebIntegrationTest
;
import
org.springframework.cloud.netflix.feign.EnableFeignClients
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RestController
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @author Dave Syer
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
FeignClientTests
.
Application
.
class
)
@WebIntegrationTest
(
randomPort
=
true
,
value
=
{
"spring.application.name=feignclienttest"
,
"logging.level.org.springframework.cloud.netflix.feign.valid=DEBUG"
,
"feign.httpclient.enabled=false"
,
"feign.okhttp.enabled=false"
})
@DirtiesContext
public
class
FeignClientTests
{
@Value
(
"${local.server.port}"
)
private
int
port
=
0
;
@Autowired
private
TestClient
testClient
;
@Autowired
private
org
.
springframework
.
cloud
.
netflix
.
feign
.
beans
.
extra
.
TestClient
extraClient
;
@Configuration
@EnableAutoConfiguration
@RestController
@EnableFeignClients
protected
static
class
Application
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
public
Hello
getHello
()
{
return
new
Hello
(
"hello world 1"
);
}
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Application
.
class
)
.
properties
(
"spring.application.name=feignclienttest"
,
"management.contextPath=/admin"
)
.
run
(
args
);
}
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public
static
class
Hello
{
private
String
message
;
}
@Test
public
void
testClient
()
{
assertNotNull
(
"testClient was null"
,
this
.
testClient
);
assertNotNull
(
"testClient was null"
,
this
.
extraClient
);
assertTrue
(
"testClient is not a java Proxy"
,
Proxy
.
isProxyClass
(
this
.
testClient
.
getClass
()));
InvocationHandler
invocationHandler
=
Proxy
.
getInvocationHandler
(
this
.
testClient
);
assertNotNull
(
"invocationHandler was null"
,
invocationHandler
);
}
@Configuration
public
static
class
TestDefaultFeignConfig
{
}
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/beans/TestClient.java
0 → 100644
View file @
82991a7f
/*
* Copyright 2013-2015 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
*
* http://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
.
cloud
.
netflix
.
feign
.
beans
;
import
org.springframework.cloud.netflix.feign.FeignClient
;
import
org.springframework.cloud.netflix.feign.beans.FeignClientTests.Hello
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"localapp"
)
public
interface
TestClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
Hello
getHello
();
}
\ No newline at end of file
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/beans/extra/TestClient.java
0 → 100644
View file @
82991a7f
/*
* Copyright 2013-2015 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
*
* http://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
.
cloud
.
netflix
.
feign
.
beans
.
extra
;
import
org.springframework.cloud.netflix.feign.FeignClient
;
import
org.springframework.cloud.netflix.feign.beans.FeignClientTests.Hello
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
@FeignClient
(
value
=
"otherapp"
)
public
interface
TestClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
Hello
getHello
();
}
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