码迷,mamicode.com
首页 > 编程语言 > 详细

springcloud17---zuul-reg-exp

时间:2018-06-09 15:25:48      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:depend   art   ica   lap   gap   toc   表达   分享   cti   

技术分享图片

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

标签:depend   art   ica   lap   gap   toc   表达   分享   cti   

原文地址:https://www.cnblogs.com/yaowen/p/9159490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!