我使用
Spring Initializer,嵌入式Tomcat,Thymeleaf模板引擎和包作为可执行JAR文件生成了一个Spring Boot Web应用程序.
使用的技术:
Spring Boot 2.0.0.M6,Java 8,maven
我在这个课程中有一个这个方法
private Map<String,Object> getErrorAttributes(HttpServletRequest request,boolean includeStackTrace) { RequestAttributes requestAttributes = new ServletRequestAttributes(request); return this.errorAttributes.getErrorAttributes(request,includeStackTrace) }
但是我不知道如何从javax.servlet.http强制转换HttpServletRequest org.springframework.web.context.request.WebRequest
The method getErrorAttributes(WebRequest,boolean) in the type ErrorAttributes is not applicable for the arguments (HttpServletRequest,boolean)
解决方法
您不需要将HttpServletRequest转换为WebRequest.您需要的是在控制器方法中使用WebRequest.
@GetMapping("/endpoint") public .. endpont(HttpServletRequest request,WebRequest webRequest) { getErrorAttributes(request,webRequest,true); }
并更改为您的getErrorAttributes方法
private Map<String,WebRequest webRequest,boolean includeStackTrace) { RequestAttributes requestAttributes = new ServletRequestAttributes(request); return this.errorAttributes.getErrorAttributes(webRequest,includeStackTrace) }