springcloud zuul
Posted yaoyu
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 zuul的主要内容,如果未能解决你的问题,请参考以下文章
ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段
imgwarp.cpp:3143: error: (-215:Assertion failed) _src.total() > 0 in function ‘warpPerspective‘(代码片段
NDK: ant 错误 [javah] Exception in thread "main" java.lang.NullPointerException 多种解决办法(代码片段
SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段
[React Testing] Use Generated Data in Tests with tests-data-bot to Improve Test Maintainability(代码片段
mvn命令异常:An error has occurred in Javadoc report generation: Unable to find javadoc command异常已解决(代码片段