搭建项目(略)
gatewa配置文件
server:
port: 9999
spring:
application:
name: gateway
cloud:
nacos:
discovery:
server-addr: localhost:8848
username: nacos
password: nacos
gateway:
routes:
- id: api-service1
uri: lb://user-login-api #服务名
predicates:
- Path=/user_login/** #匹配接口的访问路径
- id: api-service2
uri: lb://user-regist-api
predicates:
- Path=/user_regist/**
- id: api-service3
uri: lb://product-api
predicates:
- Path=/product/**
product-api配置文件
server:
port: 8003
spring:
application:
name: product-api
cloud:
nacos:
discovery:
server-addr: localhost:8848
username: nacos
password: nacos
controller
@RestController
@CrossOrigin
@RequestMapping("/product")
public class ProductController {
@GetMapping("/list")
public ResultVo list(){
System.out.println("product....list");
return new ResultVo(0,"查询商品列表成功",null);
}
@GetMapping("/get/{id}")
public ResultVo get(@PathVariable("id") Integer id){
System.out.println("product....get");
return new ResultVo(0,"查询商品详情成功",null);
}
}
postma测试