一 搭建 service-client 父模块
pom 文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>sdgt_parent</artifactId>
<groupId>com.baiyee</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service_client</artifactId>
<groupId>com.baiyee</groupId>
<packaging>pom</packaging>
<modules>
<module>service_cmn_client</module>
</modules>
<dependencies>
<dependency>
<groupId>com.baiyee</groupId>
<artifactId>common_util</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.baiyee</groupId>
<artifactId>model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<scope>provided</scope>
</dependency>
<!-- 服务调用feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
二 搭建 service-cmn-client 模块
1 pom 文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>service_client</artifactId>
<groupId>com.baiyee</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>service_cmn_client</artifactId>
<packaging>jar</packaging>
</project>
2 添加 Feign 接口类
@FeignClient(value = "service-cmn")
@Repository
public interface DictFeignClient {
// 根据 dictcode 和 value 查询
@GetMapping("/admin/cmn/dict/getName/{dictCode}/{value}")
String getName(@PathVariable("dictCode") String dictCode, @PathVariable("value") String value);
// 根据 value 查询
@GetMapping("/admin/cmn/dict/getName/{value}")
String getName(@PathVariable("value") String value);
// 获取 dictCode 对应的节点
@GetMapping("/admin/cmn/dict/getByDictCode/{dictCode}")
int getByDictCode(@PathVariable("dictCode") String dictCode);
}
三 远程调用
1 在 service 模块引入依赖
<!-- 服务调用feign -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
2 在 service_obj 模块添加依赖
<dependency>
<groupId>com.baiyee</groupId>
<artifactId>service_cmn_client</artifactId>