【发布时间】:2021-09-11 09:26:29
【问题描述】:
大部分时间使用正常,偶尔出现404。不知道怎么定位问题。
控制器文件:
@RestController
@RequestMapping("/auth")
@RequiredArgsConstructor
public class AuthController {
private final AuthService authService;
@GetMapping("info")
public Result info(@RequestParam("token") String token) {
Map<String, Object> stringObjectMap = authService.getInfo(token);
return ResultGenerator.success(stringObjectMap);
}
}
GET: localhost:9000/v1/auth/info?token=gNGLJLLZsluDsIQw 此错误消息不时显示:
{
"timestamp": "2021-06-29T06:46:35.477+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/auth/info"
}
版本信息:
- 弹簧靴:2.2.6.RELEASE
- 春云:Hoxton.SR1
追加:
spring cloud gateway yml 配置:
spring:
application:
name: gateway-service
cloud:
nacos:
discovery:
server-addr: localhost:8848
gateway:
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Origin
globalcors:
cors-configurations:
"[/**]":
allowCredentials: true
allowedOrigins: "*"
allowedHeaders: "Origin, X-Requested-With, Content-Type, Accept, Content-Length, TOKEN, Authorization"
allowedMethods: "GET, POST, PATCH, PUT, DELETE, OPTIONS"
maxAge: 3628800
discovery:
locator:
enabled: true
lower-case-service-id: true
routes:
- id: auth-service
uri: lb://auth-service
predicates:
- Path=/v1/auth/**
filters:
- StripPrefix=1
- id: bus-service
uri: lb://bus-service
predicates:
- Path=/v1/**
filters:
- StripPrefix=1
解决方案待验证
我使用了zipkin,发现路由/v1/auth/info匹配bus-service(/v1/**),所以返回404 not found。
由此得出结论:路由的写入顺序并不能保证其匹配优先级。所以必须添加order配置。
【问题讨论】:
-
我想问题不在于这个控制器。请出示你的spring cloud代码
-
@DmitriyPankratov 我添加了网关的 yml 配置
标签: java spring spring-boot http-status-code-404