Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增的接口, 请求一直报错. #36

Closed
zuihou opened this issue Nov 2, 2020 · 1 comment
Closed

新增的接口, 请求一直报错. #36

zuihou opened this issue Nov 2, 2020 · 1 comment

Comments

@zuihou
Copy link
Collaborator

zuihou commented Nov 2, 2020

版本信息:

JDK 版本(必填) : 1.8.0
源码版本(必填):2.6.0
MySQL(必填): 5.7.9
Nacos(必填):1.2.1

问题描述:

  1. 新增的接口, 或者新增服务, 前端请求报错.
  2. 新增的接口swagger 无法显示文档.

报错截图

重现步骤

@zuihou
Copy link
Collaborator Author

zuihou commented Nov 3, 2020

  1. 在自己新建服务的服务增加接口后, 想要前端调用必须在网关增加一个新建服务的路由.
// 在naocs的 zuihou-gateway-server.yml  中加入:
        - id: demo
          uri: lb://zuihou-demo-server
          predicates:
            - Path=/demo/**
          filters:
            - StripPrefix=1
  1. 假设新建服务的端口是 8080, 浏览器访问新建服务的swagger页面, http://ip:8080/doc.html 观察能否访问到你新增的Controller接口.
  2. http://ip:8080/doc.html无法访问, 但postman 访问 http://ip:8080/xxxx(你自己写的接口) 能访问, 说明服务业务代码没问题, swagger 相关配置有问题.
// 修改 zuihou-demo-server.yml
zuihou:
  swagger:
    docket:
      demo:
        title: 演示服务
        base-package: com.github.zuihou.demo.controller    // 注意调整这里的包路径
  1. http://ip:8080/doc.html无法访问, 且 postman 访问 http://ip:8080/xxxx(你自己写的接口) 也无法访问, 可能是你服务没正常启动, 观察启动报错, 访问接口时的报错. 可能有以下情况:
    4.1. 报错404: server模块没有依赖controller模块, 启动能成功,但实际该服务在启动时, 没有加载到controller模块的代码, 故无法访问. 解决方式: 在server模块加入 controller模块的依赖.
    4.2. 报错访问xx没有xx权限: 接口请求成功了, 但该接口需要指定的权限,检测到当前访问用户没有权限. 解决方案1: @PreAuth(enabled = false) 禁用权限; 方案2: 给当前用户授权, 访问时,在请求头传递userid 参数. 参考: https://github.com/zuihou/zuihou-admin-cloud/issues/35
    4.3. 报错无法正确的解析json类型的参数: 参数传错了.
  2. http://ip:8080/doc.html (该页面是直接访问新建服务)能访问, 但通过网关访问swagger文档(http://ip:8760/api/doc.html)无法显示, 则参考第1步.

总结: 通过网关访问接口无法访问时,先验证直接访问业务服务是否正常.

  1. 若业务服务能正常访问,通过网关无法访问,就是网关的配置问题.
  2. 若通过网关能访问, 独立访问业务服务不行, 则是业务服务的问题.

@zuihou zuihou closed this as completed Dec 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant