В моем приложении Spring Boot (2.1.4) мне нужно получить доступ к RequestEntity
в методе preHandle
моего перехватчика.К сожалению, мне кажется, что я не могу получить его экземпляр.
Мой код в основном такой:
@RestController
@RequestMapping("/")
public class MyController
{
@GetMapping("/")
@ResponseBody
public ResponseEntity getSomething()
// public ResponseEntity getSomething(RequestEntity<String> requestEntity) // doesn't work either
{
return new ResponseEntity<String>("test", HttpStatus.OK);
}
}
и такой перехватчик:
public class MyInterceptor extends HandlerInterceptorAdapter
{
// doesn't work:
// @Autowired RequestEntity<String> requestEntity;
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) throws Exception {}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {}
@Override
public boolean preHandle(HttpServletRequest requestServlet, HttpServletResponse responseServlet, Object handler) throws Exception
{
// ACCESS TO org.springframework.http.RequestEntity NEEDED HERE!
// NULL POINTER EXCEPTION!
requestEntity.getHeaders();
return true;
}
}
Внедряю ли я RequestEntity в контроллер или нет, мне кажется, у меня нет возможности получить доступ к (1011) (входящему) запросу.Я пытался @Autowire
перехватить его, но безрезультатно.
Есть ли способ получить к нему доступ?