前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布

Zuul

作者头像
用户5927264
发布2019-08-01 10:53:55
4820
发布2019-08-01 10:53:55
举报
文章被收录于专栏:OSChinaOSChina

1 新建微服务工程 导入需要的依赖

代码语言:javascript
复制
  <dependencies>
  		<!-- zuul路由网关 -->
		<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>
		<!-- actuator监控 -->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>
		<!-- hystrix容错 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-hystrix</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>
		<!-- 日常标配 -->
		<dependency>
			<groupId>com.shi.springCloud04</groupId>
			<artifactId>springCloud04-core</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-jetty</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
		</dependency>
		<!-- 热部署插件 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>springloaded</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
		</dependency>
  </dependencies>

2 修改yml文件

代码语言:javascript
复制
server:
  port: 9527
  
spring:
   application:
    name: zuul-getway-9527
zuul:
  prefix: /shi   #访问前缀
  ignored-services: "*"  #所有真实姓名进行隐藏
  routes:
    mydept.serviceId: SPRINGCLOUD04-PRODECT-8001  #真实访问的服务名称
    mydept.path: /mydept/**    #虚拟访问名称
      
eureka: 
  client: #客户端注册进eureka服务列表内
    service-url: 
      defaultZone: http://eureka9001.com:9001/eureka/,http://eureka9002.com:9002/eureka/,http://eureka9003.com:9003/eureka/

info:
  app.name: zuul-getway-9527
  company.name: com.shi
  build.artifactId: $project.artifactId$
  build.version: $project.version$

3 创建启动类配置启动项

代码语言:javascript
复制
package com.shi.zuul;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.zuul.EnableZuulProxy;

/**
 * 开启服务代理网关配置
 * @author SHF
 * @version 创建时间:2018年12月3日  下午4:16:35
 */
@SpringBootApplication
@EnableZuulProxy
public class SpringZuul_APP_9527 {

	public static void main(String[] args) {
			SpringApplication.run(SpringZuul_APP_9527.class, args);
	}

}

测试: http://localhost:9527/shi/mydept/dept/get/1

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
腾讯云服务器利旧
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档