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
cf615282
Commit
cf615282
authored
Oct 20, 2014
by
Dave Syer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move @Autowired into @Configuration
I prefer to keep the actual components free of autowiring, so they are easier to navigate in an IDE (i.e. you can see how they are constructed)
parent
66b4d4c6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
14 deletions
+20
-14
RibbonAutoConfiguration.java
...amework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
+17
-8
RibbonLoadBalancerClient.java
...mework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
+3
-6
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonAutoConfiguration.java
View file @
cf615282
package
org
.
springframework
.
cloud
.
netflix
.
ribbon
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.AutoConfigureAfter
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
...
...
@@ -13,10 +17,6 @@ import org.springframework.web.client.RestTemplate;
import
com.netflix.loadbalancer.BaseLoadBalancer
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author Spencer Gibb
*/
...
...
@@ -24,12 +24,16 @@ import java.util.List;
@AutoConfigureAfter
(
EurekaClientAutoConfiguration
.
class
)
public
class
RibbonAutoConfiguration
{
@Autowired
(
required
=
false
)
@Autowired
(
required
=
false
)
private
List
<
BaseLoadBalancer
>
balancers
=
Collections
.
emptyList
();
@Autowired
(
required
=
false
)
@Autowired
private
EurekaRibbonClientPreprocessor
clientPreprocessor
;
// TODO: need to find a default for this?
@Autowired
private
SpringClientFactory
springClientFactory
;
@Bean
@ConditionalOnMissingBean
(
RestTemplate
.
class
)
public
RestTemplate
restTemplate
(
RibbonInterceptor
ribbonInterceptor
)
{
...
...
@@ -43,7 +47,7 @@ public class RibbonAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
LoadBalancerClient
.
class
)
public
LoadBalancerClient
loadBalancerClient
()
{
return
new
RibbonLoadBalancerClient
(
balancers
);
return
new
RibbonLoadBalancerClient
(
clientPreprocessor
,
springClientFactory
,
balancers
);
}
@Bean
...
...
@@ -51,13 +55,18 @@ public class RibbonAutoConfiguration {
return
new
RibbonInterceptor
(
loadBalancerClient
);
}
@Configuration
protected
static
class
DefaultRibbonClientPreprocessor
{
@Bean
public
RibbonClientPreprocessor
ribbonClientPreprocessor
()
{
return
new
RibbonClientPreprocessor
()
{
@Override
public
void
preprocess
(
String
serviceId
)
{
//
no-op
//
no-op
}
};
}
}
}
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/ribbon/RibbonLoadBalancerClient.java
View file @
cf615282
...
...
@@ -4,15 +4,14 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
com.netflix.loadbalancer.AbstractLoadBalancer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerClient
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
import
com.netflix.loadbalancer.AbstractLoadBalancer
;
import
com.netflix.loadbalancer.BaseLoadBalancer
;
import
com.netflix.loadbalancer.ILoadBalancer
;
import
com.netflix.loadbalancer.Server
;
import
org.springframework.cloud.client.loadbalancer.LoadBalancerRequest
;
/**
* @author Spencer Gibb
...
...
@@ -20,15 +19,13 @@ import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest;
*/
public
class
RibbonLoadBalancerClient
implements
LoadBalancerClient
{
@Autowired
private
RibbonClientPreprocessor
ribbonClientPreprocessor
;
@Autowired
private
SpringClientFactory
clientFactory
;
private
Map
<
String
,
ILoadBalancer
>
balancers
=
new
HashMap
<
String
,
ILoadBalancer
>();
public
RibbonLoadBalancerClient
(
List
<
BaseLoadBalancer
>
balancers
)
{
public
RibbonLoadBalancerClient
(
RibbonClientPreprocessor
ribbonClientPreprocessor
,
SpringClientFactory
clientFactory
,
List
<
BaseLoadBalancer
>
balancers
)
{
for
(
BaseLoadBalancer
balancer
:
balancers
)
{
this
.
balancers
.
put
(
balancer
.
getName
(),
balancer
);
}
...
...
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