- server demo 演示
- 创建server项目
- application.properties配置
- import jar [pom.xml]
- 创建服务端的restful controller
- 验证
- openfeign client demo
- 创建client项目
- import jar【pom.xml】
- 注意 springboot与springcloud版本的一个对照 参考
- application.properties配置
- 调用服务端的client接口编码
- 客户端restful controller编码
- 客户端调用验证
- 源码
- 写在最后
spring.application.name=springboot-sample-openfeign-server server.port=8086import jar [pom.xml]
创建服务端的restful controller4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.5.RELEASE com.gaoxinfu.springboot.sample.openfeign springboot-sample-openfeign-server 1.0.0 springboot-sample-openfeign-server springboot-sample-openfeign-server pom 1.8 maven-public maven-public http://localhost:8081/repository/maven-public/ true true always warn releases Nexus Release Repository http://localhost:8081/repository/releases/ snapshots Nexus Snapshot Repository http://localhost:8081/repository/snapshots/ org.springframework.boot spring-boot-starter-web ${basedir}/src/main/webapp META-INF/resources ****
@RestController
@Controller
public class IndexController {
@PostMapping("/index")
public IndexResDto index(@RequestBody IndexReqDto indexReqDto) {
System.out.println("indexReqDto = "+indexReqDto);
return new IndexResDto(1,"gaoxinfu","man",18);
}
}
验证
openfeign client demo
创建client项目
import jar【pom.xml】
注意 springboot与springcloud版本的一个对照 参考4.0.0 org.springframework.boot spring-boot-starter-parent 2.1.5.RELEASE com.gaoxinfu.springboot.sample.openfeign springboot-sample-openfeign-client 1.0.0 springboot-sample-openfeign-client springboot-sample-openfeign-client pom 1.8 maven-public maven-public http://localhost:8081/repository/maven-public/ true true always warn releases Nexus Release Repository http://localhost:8081/repository/releases/ snapshots Nexus Snapshot Repository http://localhost:8081/repository/snapshots/ org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-openfeign org.springframework.boot spring-boot-starter-test test org.springframework.cloud spring-cloud-dependencies Greenwich.SR6 pom import ${basedir}/src/main/webapp META-INF/resources ****
https://blog.csdn.net/u014636209/article/details/125863935?csdn_share_tail=%7B%22type%22%3A%22blog%22%2C%22rType%22%3A%22article%22%2C%22rId%22%3A%22125863935%22%2C%22source%22%3A%22u014636209%22%7D&ctrtid=dXJ80
application.properties配置spring.application.name=springboot-sample-openfeign-client server.port=8085调用服务端的client接口编码
@FeignClient(name = "demo",url = "http://localhost:8086")
public interface ServerFeignClient {
@GetMapping("/index")
IndexResDto index(@RequestBody IndexReqDto indexReqDto);
}
客户端restful controller编码
@RestController
@Controller
public class DemoController {
@Resource
private ServerFeignClient serverFeignClient;
@GetMapping("/client/index")
public IndexResDto index(@RequestParam int id) {
return serverFeignClient.index(new IndexReqDto(id));
}
}
客户端调用验证
源码
https://github.com/gaoxinfu/springboot-sample/tree/master/springboot-sample-openfeign
写在最后欢迎点赞,收藏,转发,关注,一起学习,一起成长
https://github.com/gaoxinfu/springboot-sample/tree/master/springboot-sample-openfeignd现在
https://github.com/gaoxinfu/springboot-sample/tree/master/springboot-sample-openfeign



