1、建cloud-provider-payment8001
2、改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>cloud190805</artifactId> <groupId>com.atguigu.springcloud</groupId> <version>1.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>cloud-consumer-order80</artifactId> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> </project>
3、写YML
定义端口号
4、主启动
5、业务类
1、entities
2、config配置类(RestTemplate)
@Configuration public class ApplicationContextConfig { @Bean public RestTemplate restTemplate() { return new RestTemplate(); } }
3、controller
@RestController public class OrderController { public static final String PaymentSrv_URL = "http://localhost:8001"; @Autowired private RestTemplate restTemplate; @GetMapping("/consumer/payment/create") //客户端用浏览器是get请求,但是底层实质发送post调用服务端8001 public CommonResult create(Payment payment) { return restTemplate.postForObject(PaymentSrv_URL + "/payment/create",payment,CommonResult.class); } @GetMapping("/consumer/payment/get/{id}") public CommonResult getPayment(@PathVariable Long id) { return restTemplate.getForObject(PaymentSrv_URL + "/payment/get/"+id, CommonResult.class, id); } }
标签:order80,spring,boot,Module,public,org,consumer,payment From: https://www.cnblogs.com/ai377377/p/16912996.html