zoukankan      html  css  js  c++  java
  • springcloud zuul使用

    主要使用了分发的功能

    三个服务端口分别是9091 9092 9093

    现在使用zuul 统一对外暴露端口是9090

    新建一个zuul服务

    pom

        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-eureka-server</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-zuul</artifactId>
            </dependency>
    
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-devtools</artifactId>
                <version>1.5.4.RELEASE</version>
            </dependency>
    
        </dependencies>
    View Code

    启动类

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
    import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
    import org.springframework.context.annotation.Bean;
    import org.springframework.web.servlet.config.annotation.CorsRegistry;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
    import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
    
    @SpringBootApplication
    @EnableEurekaServer
    @EnableZuulProxy
    public class ZuulServerApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(ZuulServerApplication.class, args);
        }
        
        /**
         * 项目可以进行跨域请求。
         * @return
         */
        @Bean
        public WebMvcConfigurer webMvcConfigurer() {
            return new WebMvcConfigurerAdapter() {
                @Override
                public void addCorsMappings(CorsRegistry registry) {
                    registry.addMapping("/**").allowedOrigins("*").allowedMethods("*");
                }
            };
        }
    View Code

    配置文件

    server.port=9090
    eureka.client.serviceUrl.defaultZone=http://10.38.0.5:8761/eureka/
    spring.application.name=zuulserver
    zuul.routes.product.path=/product/**
    zuul.routes.product.service-id=product
    zuul.routes.order.path=/order/**
    zuul.routes.order.service-id=order

    另外的服务是product 和 order 

    service-id 是其他服务在ererka上的服务名
  • 相关阅读:
    双目对物体定位
    七个不变特征识别
    bmp和opencv格式转换
    职业规划
    input disp fprintf用法
    多线程
    访问权限
    机器人运动学仿真
    MOTOCOM32运动控制器编程
    回调函数以及钩子函数的概念
  • 原文地址:https://www.cnblogs.com/lyon91/p/10065672.html
Copyright © 2011-2022 走看看