No primary or single unique constructor found for interface javax.servlet.http.HttpServletRequest

前端发送请求需要根据token获取当前用户信息,但是一直报500,代码如下:

@GetMapping("/getCurrentMerchant")
    public Result getCurrentMerchant(HttpServletRequest request) {
        String token = request.getHeader("Authorization");
        System.out.println(token);
        Merchant currentMerchant = (Merchant) redisUtil.get("token_" + token);
        if (currentMerchant == null) {
            return Result.fail("获取当前用户信息失败!");
        }
        return Result.success("获取当前用户信息成功!", currentMerchant);
 }

此处 HttpServletRequest 导入的包为 import javax.servlet.http.HttpServletRequest;

解决办法:导入包换为:import jakarta.servlet.http.HttpServletRequest;

参考文章:请求500失败-No primary or single unique constructor found-记录SpringBoot3.0 做导出功能HttpServletResponse的导包问题_no primary or single unique constructor found for -CSDN博客

你可能感兴趣的:(后端,servlet,http,spring,boot,java)