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
9aa979cd
Commit
9aa979cd
authored
Jan 29, 2015
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
@FeignClientScan -> @EnableFeignClients
By analogy with @EnableJpaRepositories, so it's obvious that the same thing will happen (interfaces are turned into concrete @Beans).
parent
fe08762f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
41 deletions
+72
-41
EnableFeignClients.java
...ringframework/cloud/netflix/feign/EnableFeignClients.java
+2
-2
FeignAutoConfiguration.java
...framework/cloud/netflix/feign/FeignAutoConfiguration.java
+1
-23
FeignClient.java
.../org/springframework/cloud/netflix/feign/FeignClient.java
+9
-5
FeignClientFactoryBean.java
...framework/cloud/netflix/feign/FeignClientFactoryBean.java
+1
-5
FeignClientsConfiguration.java
...mework/cloud/netflix/feign/FeignClientsConfiguration.java
+52
-0
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+6
-5
FeignClientTests.java
...springframework/cloud/netflix/feign/FeignClientTests.java
+1
-1
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/
FeignClientScan
.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/
EnableFeignClients
.java
View file @
9aa979cd
...
@@ -37,8 +37,8 @@ import org.springframework.context.annotation.Import;
...
@@ -37,8 +37,8 @@ import org.springframework.context.annotation.Import;
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
@Documented
@Documented
@Import
(
FeignClientScanRegistrar
.
class
)
@Import
(
{
FeignClientsConfiguration
.
class
,
FeignClientsRegistrar
.
class
}
)
public
@interface
FeignClientScan
{
public
@interface
EnableFeignClients
{
/**
/**
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
* Alias for the {@link #basePackages()} attribute. Allows for more concise annotation
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignAutoConfiguration.java
View file @
9aa979cd
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
package
org
.
springframework
.
cloud
.
netflix
.
feign
;
package
org
.
springframework
.
cloud
.
netflix
.
feign
;
import
feign.slf4j.Slf4jLogger
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
import
org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration
;
...
@@ -28,9 +27,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -28,9 +27,7 @@ import org.springframework.context.annotation.Configuration;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
feign.Client
;
import
feign.Client
;
import
feign.Contract
;
import
feign.Feign
;
import
feign.Feign
;
import
feign.Logger
;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
...
@@ -39,28 +36,9 @@ import feign.Logger;
...
@@ -39,28 +36,9 @@ import feign.Logger;
@Configuration
@Configuration
@ConditionalOnClass
(
Feign
.
class
)
@ConditionalOnClass
(
Feign
.
class
)
@AutoConfigureAfter
(
ArchaiusAutoConfiguration
.
class
)
@AutoConfigureAfter
(
ArchaiusAutoConfiguration
.
class
)
@EnableFeignClients
public
class
FeignAutoConfiguration
{
public
class
FeignAutoConfiguration
{
@Bean
public
SpringDecoder
feignDecoder
()
{
return
new
SpringDecoder
();
}
@Bean
public
SpringEncoder
feignEncoder
()
{
return
new
SpringEncoder
();
}
@Bean
public
Logger
feignLogger
()
{
return
new
Slf4jLogger
();
}
@Bean
public
Contract
feignContract
()
{
return
new
SpringMvcContract
();
}
@ConditionalOnClass
(
ILoadBalancer
.
class
)
@ConditionalOnClass
(
ILoadBalancer
.
class
)
@Configuration
@Configuration
protected
static
class
RibbonClientConfiguration
{
protected
static
class
RibbonClientConfiguration
{
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClient.java
View file @
9aa979cd
...
@@ -24,7 +24,10 @@ import java.lang.annotation.Target;
...
@@ -24,7 +24,10 @@ import java.lang.annotation.Target;
/**
/**
* Annotation for interfaces declaring that a REST client with that interface should be
* Annotation for interfaces declaring that a REST client with that interface should be
* created (e.g. for autowiring into another component).
* created (e.g. for autowiring into another component). If ribbon is available it will be
* used to load balance the backend requests, and the load balancer can be configured
* using a <code>@RibbonClient</code> with the same name (i.e. value) as the feign client.
*
* @author Spencer Gibb
* @author Spencer Gibb
*/
*/
@Target
(
ElementType
.
TYPE
)
@Target
(
ElementType
.
TYPE
)
...
@@ -33,14 +36,15 @@ import java.lang.annotation.Target;
...
@@ -33,14 +36,15 @@ import java.lang.annotation.Target;
public
@interface
FeignClient
{
public
@interface
FeignClient
{
/**
/**
*
@return serviceId if loadbalance is true, url otherwise There is no need to prefix
*
The serviceId if loadbalance is true, or an absolute URL otherwise There is no need
* serviceId with http://.
*
to prefix
serviceId with http://.
*/
*/
String
value
();
String
value
();
/**
/**
* @return true if calls should be load balanced (assuming a load balancer is
* Set to true if calls should be load balanced (assuming a load balancer is
* available).
* available). If no load balancer is available this flag is ignored (and hence the
* {@link #value() value} should be an absolute URL).
*/
*/
boolean
loadbalance
()
default
true
;
boolean
loadbalance
()
default
true
;
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientFactoryBean.java
View file @
9aa979cd
...
@@ -106,10 +106,6 @@ class FeignClientFactoryBean implements FactoryBean<Object> {
...
@@ -106,10 +106,6 @@ class FeignClientFactoryBean implements FactoryBean<Object> {
return
builder
;
return
builder
;
}
}
protected
<
T
>
T
loadBalance
(
Class
<
T
>
type
,
String
schemeName
)
{
return
loadBalance
(
feign
(),
type
,
schemeName
);
}
protected
<
T
>
T
loadBalance
(
Feign
.
Builder
builder
,
Class
<
T
>
type
,
String
schemeName
)
{
protected
<
T
>
T
loadBalance
(
Feign
.
Builder
builder
,
Class
<
T
>
type
,
String
schemeName
)
{
builder
.
logger
(
new
Slf4jLogger
(
type
));
// TODO: how to have choice here?
builder
.
logger
(
new
Slf4jLogger
(
type
));
// TODO: how to have choice here?
if
(
this
.
ribbonClient
!=
null
)
{
if
(
this
.
ribbonClient
!=
null
)
{
...
@@ -126,7 +122,7 @@ class FeignClientFactoryBean implements FactoryBean<Object> {
...
@@ -126,7 +122,7 @@ class FeignClientFactoryBean implements FactoryBean<Object> {
this
.
schemeName
=
"http://"
+
this
.
schemeName
;
this
.
schemeName
=
"http://"
+
this
.
schemeName
;
}
}
if
(
this
.
loadbalance
)
{
if
(
this
.
loadbalance
)
{
return
loadBalance
(
this
.
type
,
this
.
schemeName
);
return
loadBalance
(
feign
(),
this
.
type
,
this
.
schemeName
);
}
}
return
feign
().
target
(
this
.
type
,
this
.
schemeName
);
return
feign
().
target
(
this
.
type
,
this
.
schemeName
);
}
}
...
...
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsConfiguration.java
0 → 100644
View file @
9aa979cd
/*
* 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
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
feign.Contract
;
import
feign.Logger
;
import
feign.slf4j.Slf4jLogger
;
/**
* @author Dave Syer
*/
@Configuration
public
class
FeignClientsConfiguration
{
@Bean
public
SpringDecoder
feignDecoder
()
{
return
new
SpringDecoder
();
}
@Bean
public
SpringEncoder
feignEncoder
()
{
return
new
SpringEncoder
();
}
@Bean
public
Logger
feignLogger
()
{
return
new
Slf4jLogger
();
}
@Bean
public
Contract
feignContract
()
{
return
new
SpringMvcContract
();
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClient
Scan
Registrar.java
→
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClient
s
Registrar.java
View file @
9aa979cd
...
@@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
...
@@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
/**
/**
* @author Spencer Gibb
* @author Spencer Gibb
*/
*/
public
class
FeignClient
Scan
Registrar
implements
ImportBeanDefinitionRegistrar
,
public
class
FeignClient
s
Registrar
implements
ImportBeanDefinitionRegistrar
,
ResourceLoaderAware
,
BeanClassLoaderAware
{
ResourceLoaderAware
,
BeanClassLoaderAware
{
// patterned after Spring Integration IntegrationComponentScanRegistrar
// patterned after Spring Integration IntegrationComponentScanRegistrar
...
@@ -50,7 +50,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -50,7 +50,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
private
ClassLoader
classLoader
;
private
ClassLoader
classLoader
;
public
FeignClient
Scan
Registrar
()
{
public
FeignClient
s
Registrar
()
{
}
}
@Override
@Override
...
@@ -91,7 +91,8 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -91,7 +91,8 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
}
}
}
}
public
BeanDefinitionHolder
createBeanDefinition
(
AnnotationMetadata
annotationMetadata
)
{
private
BeanDefinitionHolder
createBeanDefinition
(
AnnotationMetadata
annotationMetadata
)
{
Map
<
String
,
Object
>
attributes
=
annotationMetadata
Map
<
String
,
Object
>
attributes
=
annotationMetadata
.
getAnnotationAttributes
(
FeignClient
.
class
.
getCanonicalName
());
.
getAnnotationAttributes
(
FeignClient
.
class
.
getCanonicalName
());
...
@@ -121,7 +122,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -121,7 +122,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
try
{
try
{
Class
<?>
target
=
ClassUtils
.
forName
(
beanDefinition
Class
<?>
target
=
ClassUtils
.
forName
(
beanDefinition
.
getMetadata
().
getClassName
(),
.
getMetadata
().
getClassName
(),
FeignClient
Scan
Registrar
.
this
.
classLoader
);
FeignClient
s
Registrar
.
this
.
classLoader
);
return
!
target
.
isAnnotation
();
return
!
target
.
isAnnotation
();
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
...
@@ -140,7 +141,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
...
@@ -140,7 +141,7 @@ public class FeignClientScanRegistrar implements ImportBeanDefinitionRegistrar,
protected
Set
<
String
>
getBasePackages
(
AnnotationMetadata
importingClassMetadata
)
{
protected
Set
<
String
>
getBasePackages
(
AnnotationMetadata
importingClassMetadata
)
{
Map
<
String
,
Object
>
attributes
=
importingClassMetadata
Map
<
String
,
Object
>
attributes
=
importingClassMetadata
.
getAnnotationAttributes
(
FeignClientScan
.
class
.
getCanonicalName
());
.
getAnnotationAttributes
(
EnableFeignClients
.
class
.
getCanonicalName
());
Set
<
String
>
basePackages
=
new
HashSet
<>();
Set
<
String
>
basePackages
=
new
HashSet
<>();
for
(
String
pkg
:
(
String
[])
attributes
.
get
(
"value"
))
{
for
(
String
pkg
:
(
String
[])
attributes
.
get
(
"value"
))
{
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/FeignClientTests.java
View file @
9aa979cd
...
@@ -91,7 +91,7 @@ public class FeignClientTests {
...
@@ -91,7 +91,7 @@ public class FeignClientTests {
@Configuration
@Configuration
@EnableAutoConfiguration
@EnableAutoConfiguration
@RestController
@RestController
@
FeignClientScan
@
EnableFeignClients
@RibbonClient
(
name
=
"localapp"
,
configuration
=
LocalRibbonClientConfiguration
.
class
)
@RibbonClient
(
name
=
"localapp"
,
configuration
=
LocalRibbonClientConfiguration
.
class
)
protected
static
class
Application
{
protected
static
class
Application
{
...
...
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