1.静态路由
1.1配置实现
1.2bean实现
2.动态路由 通过微服务名称而不是localhost:
1.静态路由
1.1配置实现
1.2bean实现
config.GateWayConfig-RouteLocatorBuilder
//当访问地址http://localhost:9527/guonei时,会自动转发到地址 http://news.baidu.com/guonei
@Configuration
public class GateWayConfig
{
@Bean
public RouteLocator customRouteLocator(RouteLocatorBuilder routeLocatorBuilder)
{
//1.声明
RouteLocatorBuilder.Builder routes = routeLocatorBuilder.routes();
routes.route("path_route_tang", //id
r -> r.path("/guonei") //网址对应的url 国内
.uri("http://news.baidu.com/guonei")).build();
return routes.build();
}
}
2.动态路由 通过微服务名称而不是localhost:
测试:
http://localhost:9527/payment/lb 会出来8001 8002