美文网首页
基于Spring Cloud zuul实现网关服务后访问/rou

基于Spring Cloud zuul实现网关服务后访问/rou

作者: 南湘嘉荣 | 来源:发表于2021-05-16 12:48 被阅读0次

首先我的环境如下:

Spring Boot 2.2.5.RELEASE
Spring Cloud Hoxton.SR8

按照相关技术资料显示,当我们完成 zuul 网关服务器的搭建之后。即使不配置任何路由信息,zuul 也会默认使用 Eureka 服务的服务ID,并将其映射到相应的下游服务实例。

这就是基于服务发现的自动映射路由。

也就是说,我们可以通过 zuul 服务器暴露的端点/routes来查看 zuul 服务器管理的路由。即访问:

http://localhost:5555/routes

但是,实际上我们得到的结果却是这样:Not Found 404。

问题出在哪里?

经过查询资料,终于找到答案。

在项目中,我们引入的依赖是:

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

这个依赖,默认引入了spring-boot-starter-actuator。

这样一来原来的/routes访问路径就变了。

应该是:

http://localhost:5555/actuator/routes

但是,如果就这样你还是查看不到路由列表。因为,默认情况下 actuator 插件不将 routes 端点暴露出来。所以还要在 application.yml 文件中配置一下:

management:
  endpoints:
    web:
      exposure:
        include: routes

大功告成。

相关文章

网友评论

      本文标题:基于Spring Cloud zuul实现网关服务后访问/rou

      本文链接:https://www.haomeiwen.com/subject/ebgljltx.html