SpringBoot整合zuul

pom.xml

 <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
    </dependency>
     <!--eureka客户端-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>

bootstrap.xml

server:
  port: 9600
spring: 
  application:  
    name: gateway #指定服务名
  servlet:
    multipart:
      max-request-size: 20MB
      max-file-size: 20MB
eureka:
  instance:
    hostname: cetc-gateway
    prefer-ip-address: true
  client:
    registerWithEureka: true #是否将自己注册到Eureka服务中
    fetchRegistry: true #要在本地缓存注册表信息
    service-url:
      defaultZone: http://cetc-eureka:1111/eureka
zuul:
  sensitive-headers:        #敏感header的设置,此处为空,默认Authorization不被转发
  #  ignored-services: '*'    #该配置关闭,则zuul会默认代理所有注册在Eureka上的微服务
  routes:
    cetc-admin:              #路由的一个名称,可以任意起名
      path: /api-admin/** #拦截到的路径
      serviceId:admin #模块的服务名
    cetc-log:
      path: /api-log/**
      serviceId: cetc-log

zuul还可以设置某些路径,不暴露给请求客户端->详细信息

application.java

//在启动类上添加注解@EnableZuulProxy,声明一个zuul代理。
// 代码中的@EnableDiscoveryClient注解为Eureka的客户端注解。
@SpringBootApplication
@EnableZuulProxy
@EnableFeignClients
public class ZuulServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ZuulServerApplication.class);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值