springcloud17---zuul-reg-exp
Posted 672530440
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了springcloud17---zuul-reg-exp相关的知识,希望对你有一定的参考价值。
package com.itmuch.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; import org.springframework.cloud.netflix.zuul.filters.discovery.PatternServiceRouteMapper; import org.springframework.context.annotation.Bean; @SpringBootApplication @EnableZuulProxy public class ZuulApplication { public static void main(String[] args) { SpringApplication.run(ZuulApplication.class, args); } //正则表达式路由规则: //name-version映射成version/name //用户微服务通过http://192.168.88.1:7901/simple/1访问,user微服务名字是microservice-provider-user-v1-v2 //通过http://192.168.88.1:8040/v2/microservice-provider-user-v1/simple/1就可以访问user微服务 @Bean public PatternServiceRouteMapper serviceRouteMapper() { return new PatternServiceRouteMapper("(?<name>^.+)-(?<version>v.+$)", "${version}/${name}"); } }
spring: application: name: microservice-gateway-zuul server: port: 8040 eureka: client: service-url: defaultZone: http://user:password123@localhost:8761/eureka instance: prefer-ip-address: true
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.itmuch.cloud</groupId>
<artifactId>microservice-spring-cloud</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>microservice-gateway-zuul-reg-exp</artifactId>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
</project>
以上是关于springcloud17---zuul-reg-exp的主要内容,如果未能解决你的问题,请参考以下文章
SpringCloud系列SpringCloud概述及微服务技术栈的使用