Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我可以在其他地方使用请求头,但不能在方法调用中使用吗?_Java_Spring_Spring Boot_Annotations_Swagger Ui - Fatal编程技术网

Java 我可以在其他地方使用请求头,但不能在方法调用中使用吗?

Java 我可以在其他地方使用请求头,但不能在方法调用中使用吗?,java,spring,spring-boot,annotations,swagger-ui,Java,Spring,Spring Boot,Annotations,Swagger Ui,是否可以在方法参数列表之外的任何其他位置设置@RequestHeader注释?下面您可以看到我的代码: @ApiOperation("Gather all details of a specific device, identified by its ID") @ApiResponses(value = { @ApiResponse(code = 200, message = "OK", response = DeviceResource.class), @Api

是否可以在方法参数列表之外的任何其他位置设置@RequestHeader注释?下面您可以看到我的代码:

@ApiOperation("Gather all details of a specific device, identified by its ID")
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "OK", response = DeviceResource.class),
        @ApiResponse(code = 404, message = "Device not found", response = VndErrors.class),
        @ApiResponse(code = 500, message = "Printer shell execution error", response = VndErrors.class)
})
@GetMapping("/{id}")
public ResponseEntity<DeviceResource> getDeviceById(
        @ApiParam(value = "ID of the device", required = true)
        @PathVariable String id,
        @RequestHeader(name = "X-NANO-APIKEY") String auth
) {
    return ResponseEntity.ok(new DeviceResource(deviceAccessor.getDeviceById(id)));
}
@ApiOperation(“收集特定设备的所有详细信息,由其ID标识”)
@ApiResponses(值={
@ApiResponse(代码=200,消息=“OK”,响应=DeviceResource.class),
@ApiResponse(code=404,message=“未找到设备”,response=VndErrors.class),
@ApiResponse(code=500,message=“打印机外壳执行错误”,response=VndErrors.class)
})
@GetMapping(“/{id}”)
公共响应getDeviceById(
@ApiParam(value=“设备的ID”,必需=true)
@路径变量字符串id,
@RequestHeader(name=“X-NANO-APIKEY”)字符串身份验证
) {
返回ResponseEntity.ok(新的DeviceResource(deviceAccessor.getDeviceById(id));
}

问题是我对其他调用也使用了这个方法,所以我必须在这种情况下设置头。但我不想设定它。我只需要在大摇大摆的ui中设置它。感谢您的帮助。

您也可以从HttpServletRequest对象检索请求头

public ResponseEntity<DeviceResource> getDeviceById(
@ApiParam(value = "ID of the device", required = true)
@PathVariable String id,
HttpServletRequest request
) {
String auth = request.getHeader("X-NANO-APIKEY");
}
public ResponseEntity getDeviceById(
@ApiParam(value=“设备的ID”,必需=true)
@路径变量字符串id,
HttpServletRequest请求
) {
字符串auth=request.getHeader(“X-NANO-APIKEY”);
}

希望有帮助。

我有一个问题,我无法在Swigger ui中设置它:/n您可以在摘要定义中使用
globalOperationParameters