feat: 增加加载感知类
This commit is contained in:
parent
839ce671d7
commit
17adfebe5b
@ -4,7 +4,7 @@ Rest Proxy组件是本人在长期的系统对接工作中提炼出的一个可
|
||||
具体是这样的:**写一个interface,定义几个method,然后加上注解,完成!**,在业务里直接调用method即可,不需要写任何实现类!
|
||||
|
||||
## REST请求代理(基于Http Interface)
|
||||
本组件基于SpringBoot2.7.7构建,支持完整的AutoConfiguraiton。仅需要极少量配置就可以完成配置。当前最新版本为`1.1.2`,新增了标准REST注解。
|
||||
本组件基于SpringBoot2.7.7构建,支持完整的AutoConfiguraiton。仅需要极少量配置就可以完成配置。当前最新版本为`1.1.3`,新增了标准REST注解。
|
||||
|
||||
### 特性列表
|
||||
- 无感知自动注入,只需interface + 注解即可轻松完成对接
|
||||
@ -29,7 +29,7 @@ Rest Proxy组件是本人在长期的系统对接工作中提炼出的一个可
|
||||
<dependency>
|
||||
<groupId>group.flyfish</groupId>
|
||||
<artifactId>rest-proxy-core</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.3</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
4
pom.xml
4
pom.xml
@ -13,7 +13,7 @@
|
||||
|
||||
<groupId>group.flyfish</groupId>
|
||||
<artifactId>rest-proxy</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.3</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
@ -22,7 +22,7 @@
|
||||
<java.version>1.8</java.version>
|
||||
<commons-collection.version>4.4</commons-collection.version>
|
||||
<commons.lang.version>2.6</commons.lang.version>
|
||||
<sdk.version>1.1.2</sdk.version>
|
||||
<sdk.version>1.1.3</sdk.version>
|
||||
</properties>
|
||||
|
||||
<packaging>pom</packaging>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>group.flyfish</groupId>
|
||||
<artifactId>rest-proxy</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package group.flyfish.rest.configuration;
|
||||
|
||||
/**
|
||||
* rest客户端加载感知
|
||||
*
|
||||
* @author wangyu
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface RestLoadedAware {
|
||||
|
||||
/**
|
||||
* 所有客户端完成加载
|
||||
*/
|
||||
void onClientsLoaded();
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>group.flyfish</groupId>
|
||||
<artifactId>rest-proxy</artifactId>
|
||||
<version>1.1.2</version>
|
||||
<version>1.1.3</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -11,11 +11,11 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -57,15 +57,22 @@ public class RestClientProperties implements InitializingBean {
|
||||
* 修改器们
|
||||
*/
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private List<RestPropertiesModifier> modifiers;
|
||||
@Setter(onMethod_ = @Autowired)
|
||||
private ObjectProvider<RestPropertiesModifier> modifiers;
|
||||
|
||||
/**
|
||||
* 配置感知项
|
||||
*/
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(AccessLevel.NONE)
|
||||
private List<PropertiesConfigurable> configures;
|
||||
@Setter(onMethod_ = @Autowired)
|
||||
private ObjectProvider<PropertiesConfigurable> configures;
|
||||
|
||||
/**
|
||||
* 加载感知
|
||||
*/
|
||||
@Getter(AccessLevel.NONE)
|
||||
@Setter(onMethod_ = @Autowired)
|
||||
private ObjectProvider<RestLoadedAware> aware;
|
||||
|
||||
/**
|
||||
* 获取字典url
|
||||
@ -80,29 +87,20 @@ public class RestClientProperties implements InitializingBean {
|
||||
return urls.get(key);
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setDefaultAuthProvider(RestAuthProvider provider) {
|
||||
this.authProvider = provider;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setModifiers(List<RestPropertiesModifier> modifiers) {
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setConfigures(List<PropertiesConfigurable> configures) {
|
||||
this.configures = configures;
|
||||
@Autowired
|
||||
public void setDefaultAuthProvider(ObjectProvider<RestAuthProvider> provider) {
|
||||
this.authProvider = provider.getIfAvailable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
if (DataUtils.isNotEmpty(modifiers)) {
|
||||
modifiers.forEach(modifier -> modifier.modify(this));
|
||||
}
|
||||
if (DataUtils.isNotEmpty(configures)) {
|
||||
configures.forEach(item -> item.configure(this));
|
||||
}
|
||||
// 配置修改
|
||||
modifiers.forEach(modifier -> modifier.modify(this));
|
||||
// 服务初始化
|
||||
RestInvokers.configure(this);
|
||||
// 配置感知
|
||||
configures.forEach(item -> item.configure(this));
|
||||
// 加载感知
|
||||
aware.forEach(RestLoadedAware::onClientsLoaded);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user