springcloud的zuul与configserver结合

本文介绍如何在微服务架构中使用Zuul作为API网关,并详细解释了如何通过配置中心来管理路由规则和服务标识。包括依赖项配置、属性文件设置等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有了配置中心,所以微服务项目中application.properties文件的内容都可以提取到配置中心(除了连接配置中心属性)

1.配置中心中加入属性文件,zuul-gateway-[test|dev].properties

   

# web
zuul.routes.api-web.path=/web/**
zuul.routes.api-web.serviceId=front-service
# mobile
#zuul.routes.api-mobile.path=/mobile/**
#zuul.routes.api-mobile.serviceId=mobile-service

 

2.zuul依赖如下

 

<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zuul</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-config</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-eureka</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-actuator</artifactId>
		</dependency>

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-test</artifactId>
			<scope>test</scope>
		</dependency>

 3.zuul中添加文件bootstrap.properties,删除application.properties

 

   

#对应配置中心的属性文件前缀
spring.application.name=zuul-gateway
server.port=5555
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=config-server
spring.cloud.config.profile=dev

 

 

1

1

1

1

1

1

1

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值