新建项目spring-cloud-zuul-service
添加依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency>
开启服务注册
在程序的启动类 ZuulApplication
通过 @EnableZuulProxy
开启 Zuul 服务网关
@EnableZuulProxy @SpringBootApplication public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); } }
添加配置
配置文件 application.yml
spring: application: name: zuul-service server: port: 9000 zuul: routes: blog: path: /ymq/** url: http://www.xxx.io/about