网关的作用
是为服务的入口,需要通过网关我们经行,登录认证,流量限制,请求监控,请求分发等等。
还是复制一份以前写过的代码,只需要主配置类,和配置文件就可以了
导包
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency>
配置文件
如果想直接通过服务器名称访问我们可以通过不配置zuul直接访问http://localhost:4000/order-server/customer/user/1
eureka: client: serviceUrl: defaultZone: http://localhost:1000/eureka/#注册中心地址 instance: ip-address: true #使用ip配置 instance-id: zuul-server #指定服务的idserver: port: 4000spring: application: name: zuul-serverzuul: ignoredServices: '*' #不允许使用服务名称访问,这里是指的application:name,开启这个配置的时候我们需要开启routes prefix: /hrm #统一前缀 routes: order-server: /order/** #类似于取别名,这样访问order-server的时候就可以通过order来访问
访问方式