一:创建微服务消费者工程_chserivcecloud-consumer-dept-80
1、选中父工程右击---->new Other--->Maven Module
2、创建的方式和之前一样只不过工程名称不一样
二:编写POM.xml文件
三:编写.yml文件
1、在该工程的src/main/resources下创建application.yml文件
四:创建ConfigBean类替换Spring的Application.xml
1、在当前的工程src/main/java下创建com.ch.springcloud.cfgbears
2、并创建ConfigBean类替代Spring的Application.xml,使用注解创建对象Bean
五:创建controller层
1、RestTemplate 描述
1、RestTemplate提供了多种便捷的远程访问Http服务器的方法
2、是一种简单的快捷的访问Rest服务模版,Spring提供用于访问Rest服务客户端模版的工具集
3、官网:https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/client/RestTemplate.html
2、controller层
1、在当前的工程src/main/java下创建com.ch.springcloud.controller
2、并创建DeptController_Consumer类
3、 这里的restTemplate.postForObject(REST请求的地址(提供者的地址),请求的参数,HTTP响应转换被转换是的对象)
五:DeptConsumer80_Ch主启动类
1、在当前的工程com.ch.springcloud下进行创建
六:启动测试
1、提供(8001)和消费者(80)都需要提供
2、消费者(80)
3、提供(8001)同之前一样启动
1、消费者(80)进行访问
1、查询所有:http://localhost/consumer/dept/list
2、查询单个:http://localhost/consumer/dept/get/2
3、添加:http://localhost/consumer/dept/add?dname=admin