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
ab454f1e
Commit
ab454f1e
authored
Jan 09, 2017
by
Ryan Baxter
Committed by
Spencer Gibb
Jan 09, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make FeignClientRegistrar implement EnvironmentAware (#1569)
Make FeignClientRegistrar implement EnvironmentAware to inject the environment. Fixes gh-1568
parent
bd6d732f
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
140 additions
and
2 deletions
+140
-2
FeignClientsRegistrar.java
...gframework/cloud/netflix/feign/FeignClientsRegistrar.java
+11
-2
TestClient.java
...framework/cloud/netflix/feign/testclients/TestClient.java
+32
-0
FeignClientEnvVarTests.java
.../netflix/feign/valid/scanning/FeignClientEnvVarTests.java
+97
-0
No files found.
spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/feign/FeignClientsRegistrar.java
View file @
ab454f1e
...
...
@@ -37,10 +37,12 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import
org.springframework.beans.factory.support.BeanDefinitionReaderUtils
;
import
org.springframework.beans.factory.support.BeanDefinitionRegistry
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.EnvironmentAware
;
import
org.springframework.context.ResourceLoaderAware
;
import
org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider
;
import
org.springframework.context.annotation.ImportBeanDefinitionRegistrar
;
import
org.springframework.core.annotation.AnnotationAttributes
;
import
org.springframework.core.env.Environment
;
import
org.springframework.core.io.ResourceLoader
;
import
org.springframework.core.type.AnnotationMetadata
;
import
org.springframework.core.type.ClassMetadata
;
...
...
@@ -59,7 +61,7 @@ import org.springframework.util.StringUtils;
* @author Venil Noronha
*/
class
FeignClientsRegistrar
implements
ImportBeanDefinitionRegistrar
,
ResourceLoaderAware
,
BeanClassLoaderAware
{
ResourceLoaderAware
,
BeanClassLoaderAware
,
EnvironmentAware
{
// patterned after Spring Integration IntegrationComponentScanRegistrar
// and RibbonClientsConfigurationRegistgrar
...
...
@@ -68,6 +70,8 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
private
ClassLoader
classLoader
;
private
Environment
environment
;
public
FeignClientsRegistrar
()
{
}
...
...
@@ -272,7 +276,7 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
}
protected
ClassPathScanningCandidateComponentProvider
getScanner
()
{
return
new
ClassPathScanningCandidateComponentProvider
(
false
)
{
return
new
ClassPathScanningCandidateComponentProvider
(
false
,
this
.
environment
)
{
@Override
protected
boolean
isCandidateComponent
(
...
...
@@ -373,6 +377,11 @@ class FeignClientsRegistrar implements ImportBeanDefinitionRegistrar,
builder
.
getBeanDefinition
());
}
@Override
public
void
setEnvironment
(
Environment
environment
)
{
this
.
environment
=
environment
;
}
/**
* Helper class to create a {@link TypeFilter} that matches if all the delegates
* match.
...
...
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/testclients/TestClient.java
0 → 100644
View file @
ab454f1e
/*
*
* * Copyright 2013-2016 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
.
testclients
;
import
org.springframework.cloud.netflix.feign.FeignClient
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
/**
* @author Ryan Baxter
*/
@FeignClient
(
name
=
"localapp"
)
public
interface
TestClient
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
String
getHello
();
}
spring-cloud-netflix-core/src/test/java/org/springframework/cloud/netflix/feign/valid/scanning/FeignClientEnvVarTests.java
0 → 100644
View file @
ab454f1e
/*
*
* * Copyright 2013-2016 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
.
valid
.
scanning
;
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.context.SpringBootTest
;
import
org.springframework.cloud.netflix.feign.EnableFeignClients
;
import
org.springframework.cloud.netflix.feign.testclients.TestClient
;
import
org.springframework.cloud.netflix.ribbon.RibbonClient
;
import
org.springframework.cloud.netflix.ribbon.StaticServerList
;
import
org.springframework.context.annotation.Bean
;
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
com.netflix.loadbalancer.Server
;
import
com.netflix.loadbalancer.ServerList
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
/**
* @author Ryan Baxter
*/
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringBootTest
(
classes
=
FeignClientEnvVarTests
.
Application
.
class
,
webEnvironment
=
SpringBootTest
.
WebEnvironment
.
RANDOM_PORT
,
value
=
{
"spring.application.name=feignclienttest"
,
"feign.httpclient.enabled=false"
,
"basepackage=org.springframework.cloud.netflix.feign.testclients"
})
@DirtiesContext
public
class
FeignClientEnvVarTests
{
@Autowired
private
TestClient
testClient
;
@Test
public
void
testSimpleType
()
{
String
hello
=
this
.
testClient
.
getHello
();
assertNotNull
(
"hello was null"
,
hello
);
assertEquals
(
"first hello didn't match"
,
"hello world 1"
,
hello
);
}
@Configuration
@EnableAutoConfiguration
@RestController
@EnableFeignClients
(
basePackages
=
{
"${basepackage}"
})
@RibbonClient
(
name
=
"localapp"
,
configuration
=
LocalRibbonClientConfiguration
.
class
)
protected
static
class
Application
{
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/hello"
)
public
String
getHello
()
{
return
"hello world 1"
;
}
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
Application
.
class
)
.
properties
(
"spring.application.name=feignclienttest"
,
"management.contextPath=/admin"
)
.
run
(
args
);
}
}
// Load balancer with fixed server list for "local" pointing to localhost
@Configuration
public
static
class
LocalRibbonClientConfiguration
{
@Value
(
"${local.server.port}"
)
private
int
port
=
0
;
@Bean
public
ServerList
<
Server
>
ribbonServerList
()
{
return
new
StaticServerList
<>(
new
Server
(
"localhost"
,
this
.
port
));
}
}
}
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