这个模块是一个独立的模块所以需要建立一个模块,
首先引入:
依赖pom.xml
<?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>springcloud-parent</artifactId> <groupId>com.cxy</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>springcloud-zuul</artifactId> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-zuul</artifactId> </dependency> </dependencies> </project>
编写启动类:
package com.cxy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; /*** * @ClassName: ZuulApplication * @Description: * @Auther: cxy * @Date: 2019/1/29:12:48 * @version : V1.0 */ @SpringBootApplication @EnableZuulProxy public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class,args); } }
编写yml文件:
server: port: 8083 spring: application: name: cxy-zuul-service eureka: client: service-url: defaultZone: http://admin:admin@127.0.0.1:8761/eureka/ instance: prefer-ip-address: true zuul: routes: spring-person: #服务工程名字 path: /person/** #配置url请求规则 serviceId: cxy-person-service #服务名称 spring-user: path: /user/** erviceId: cxy-user-service
注意事项:
二:
访问体验: