• springcloud zuul


    新建工程spring-cloud-zuul

    pom.xml

    <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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    	<groupId>consul-test</groupId>
    	<artifactId>zuul-test</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<name>consul-test</name>
    	<packaging>jar</packaging>
    	<description>zuul-test</description>
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.0.0.RELEASE</version>
    	</parent>
    	<dependencyManagement>
    		<dependencies>
    			<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> 
    				<version>2.0.0.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> -->
    			<dependency>
    				<groupId>org.springframework.cloud</groupId>
    				<artifactId>spring-cloud-dependencies</artifactId>
    				<version>Finchley.M8</version>
    				<type>pom</type>
    				<scope>import</scope>
    			</dependency>
    		</dependencies>
    	</dependencyManagement>
    	<dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
            </dependency>
    		<dependency>
    			<groupId>org.springframework.cloud</groupId>
    			<artifactId>spring-cloud-starter-consul-discovery</artifactId>
    		</dependency>
    	</dependencies>
    </project>
    

      application.properties

    spring.application.name=spring-cloud-zuul
    server.port=8506
    zuul.routes.spring-cloud-consul-producer.path=/service-producer/**
    #zuul.routes.spring-cloud-consul-producer.service-id=service-producer

      bootstrap.yml

    spring:
      cloud:
        config:
          uri: http://localhost:8500
    

      demo启动代码

    package test;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
    import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
    import org.springframework.web.bind.annotation.RestController;
    
    @SpringBootApplication
    @EnableDiscoveryClient
    @EnableZuulProxy
    @RestController
    public class Application {
    	public static void main(String[] args) {
    		SpringApplication.run(Application.class, args);
    	}
    
    }
    

    启动之前的SpringCloudConsulProducerApplication,然后启动Application

    在consul上可以看到注册的服务,http://127.0.0.1:8500/ui/dc1/services

    除了consul自身外,有两个:service-producer和spring-cloud-zuul

    使用zuul的ip和端口访问producer的hello接口:http://127.0.0.1:8506/service-producer/hello

    可以正常访问。

  • 相关阅读:
    基于springcloud框架搭建项目-Eureka篇(一)
    springcloud项目实现自定义权限注解进行接口权限验证
    基于JWT实现token验证
    前端${}失效
    String常见的方法有哪些?
    Json转化的三种方式
    字符串、bute[]数组和十六进制字符串的相互转换
    Sql Server2008温故而知新系列05:查询-基础查询和条件查询
    Sql Server2008温故而知新系列04:数据增删改查之"改"
    Sql Server2008温故而知新系列03:数据增删改查之"删"
  • 原文地址:https://www.cnblogs.com/yaoyu1983/p/12444095.html
Copyright © 2020-2023  润新知