【问题标题】:Request Mapping not working after upgrading to Spring boot 2.x升级到 Spring boot 2.x 后请求映射不起作用
【发布时间】:2018-08-10 01:39:49
【问题描述】:

我有以下在 Spring boot 1.x 中运行良好的控制器:

@Log4j2
@RestController
@RequestMapping(value = "/delivery/{id}")
public class DeliveryController {

    @Autowired
    private DeliveryService deliveryService;

    /**
     * request mapping of http GET method.
     *
     * @param id    
     * @param serviceId id
     * @param accessKey password
     * @param request   use for log output only
     * @return MyDeliveryDto data exist 200(OK) : data not exist 204(NO_CONTENT)
     * @throws ServiceUnavailableException When the maintenance flag is true in the application.yml.
     * @throws UnAuthorizedException       serviceid and accessKey invalid.
     * @throws ForbiddenException          serviceID not registered in application.yml.
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity<MyDeliveryDto> get(@PathVariable Long id,
                                             String serviceId,
                                             String accessKey,
                                             HttpServletRequest request)
            throws ServiceUnavailableException, UnAuthorizedException, ForbiddenException {
        MyDeliveryDto dto = deliveryService.select(id, serviceId, accessKey);
        log.info("response dto : {}, serviceId : {}", dto, serviceId);
        if (Objects.isNull(dto)) {
            return new ResponseEntity<>(HttpStatus.NO_CONTENT);
        }
        return new ResponseEntity<MyDeliveryDto>(dto, HttpStatus.OK);
    }
}

但是升级到Spring boot 2.0.4后,出现如下错误:

{
    "timestamp": "2018/08/10T10:35:59.459+0900",
    "status": 404,
    "error": "Not Found",
    "message": "No message available",
    "path": "/mydata-api/delivery/123"
}

我在迁移到新版本时是否遗漏了什么?

【问题讨论】:

  • @ResponseBody 是重复的,需要删除它
  • 是的,也试过了,还是一样的问题

标签: spring rest spring-mvc spring-boot


【解决方案1】:

发现问题 - 上下文路径配置已移至 server.servlet.context-path,因此旧的 server.context-path 已弃用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-30
    • 2019-11-25
    • 2014-05-15
    • 1970-01-01
    • 2019-04-16
    • 2014-06-12
    • 2016-06-27
    • 2023-01-19
    相关资源
    最近更新 更多