-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Kurok1/dev
support feign load component from main beanFactory
- Loading branch information
Showing
12 changed files
with
90 additions
and
60 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
...openfeign/src/main/java/io/microsphere/spring/cloud/openfeign/FeignComponentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.microsphere.spring.cloud.openfeign; | ||
|
||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.beans.factory.BeanFactoryAware; | ||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory; | ||
import org.springframework.cloud.context.named.NamedContextFactory; | ||
import org.springframework.cloud.openfeign.FeignClientSpecification; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">韩超</a> | ||
* @since 0.0.1 | ||
*/ | ||
public class FeignComponentProvider implements BeanFactoryAware { | ||
|
||
private final NamedContextFactory<FeignClientSpecification> contextFactory; | ||
|
||
private BeanFactory mainBeanFactory; | ||
|
||
public FeignComponentProvider(NamedContextFactory<FeignClientSpecification> contextFactory) { | ||
this.contextFactory = contextFactory; | ||
} | ||
|
||
public <T> T getInstance(String contextName, Class<T> type) { | ||
T component = this.contextFactory.getInstance(contextName, type); | ||
if (component == null && mainBeanFactory instanceof AutowireCapableBeanFactory) { | ||
//create new | ||
return ((AutowireCapableBeanFactory)this.mainBeanFactory).createBean(type); | ||
} | ||
return component; | ||
} | ||
|
||
@Override | ||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException { | ||
this.mainBeanFactory = beanFactory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.