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上的服务名
  • 相关阅读:
    mycat的基本介绍及安装
    mycat的安装及使用
    java 基本语法(十三) 数组(六)数组的常见异常
    java 面向对象(一):类与对象
    java 面向对象(二):JVM内存结构
    java 面向对象(三):类结构 属性
    java 面向对象(五):类结构 方法(二) 关键字:return;方法的重载;可变个数形参的方法
    Salesforce数据安全简介
    Apex计划作业框架的实现
    异步 Apex 类
  • 原文地址:https://www.cnblogs.com/lyon91/p/10065672.html
Copyright © 2011-2022 走看看