Skip to content

Commit

Permalink
* 远程绑定feign解耦优化
Browse files Browse the repository at this point in the history
  • Loading branch information
Scorrt-2021 committed Jan 10, 2023
1 parent 764728d commit e2d20c0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
30 changes: 9 additions & 21 deletions diboot-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<artifactId>spring-jdbc</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand All @@ -56,24 +57,11 @@
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<!-- openfeign可选依赖 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-openfeign-core</artifactId>
<version>3.1.5</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>

</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
*/
package com.diboot.core.binding.binder.remote;

import com.diboot.core.util.ContextHelper;
import com.diboot.core.exception.InvalidUsageException;
import com.diboot.core.util.ContextHolder;
import com.diboot.core.util.JSON;
import com.diboot.core.util.V;
import com.diboot.core.vo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FeignClientBuilder;

import java.util.Collections;
import java.util.List;
Expand All @@ -41,10 +41,6 @@ public class RemoteBindingManager {
* restTemplate 实例缓存
*/
private static Map<String, RemoteBindingProvider> MODULE_PROVIDER_MAP;
/**
* feignClientBuilder 实例
*/
private static FeignClientBuilder feignClientBuilder;

/**
* 从远程接口抓取 Entity List
Expand Down Expand Up @@ -78,10 +74,11 @@ private synchronized static RemoteBindingProvider getRemoteBindingProvider(Strin
MODULE_PROVIDER_MAP = new ConcurrentHashMap<>();
}
return MODULE_PROVIDER_MAP.computeIfAbsent(module, key -> {
if(feignClientBuilder == null){
feignClientBuilder = new FeignClientBuilder(ContextHelper.getApplicationContext());
RemoteBindingProviderFactory factory = ContextHolder.getBean(RemoteBindingProviderFactory.class);
if(factory == null) {
throw new InvalidUsageException("RemoteBindingProviderFactory 未实现,无法使用远程绑定功能!");
}
return feignClientBuilder.forType(RemoteBindingProvider.class, module).build();
return factory.create(module);
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.diboot.core.binding.binder.remote;

/**
* 远程绑定工厂类
* @author JerryMa
* @version v3.0.0
* @date 2023/1/10
* Copyright © diboot.com
*/
public interface RemoteBindingProviderFactory {

/**
* 创建provider实例
* @param module
* @return
*/
RemoteBindingProvider create(String module);

}

0 comments on commit e2d20c0

Please sign in to comment.