Hello! Faced a problem, searches did not lead to anything. I process sql errors from the database in my controllers and send them to the front:

@ExceptionHandler(DataException.class) @ResponseBody public ResponseEntity<String> handleException(DataException e, HttpServletResponse response) { log.error(e); response.setContentType("application/json;charset=UTF-8"); response.setHeader("Content-Type", "application/json; charset=utf-8"); response.setCharacterEncoding("UTF-8"); if (e.getRootCause() instanceof SQLException) { SQLException s = (SQLException) e.getRootCause(); // return CommonUtil.getErrorResponse(ErrorToResponse.getJsonSqlError(s.getMessage(), s.getSQLState())); return new ResponseEntity<String>("ТУТ РУССКИЙ ЯЗЫК!", HttpStatus.INTERNAL_SERVER_ERROR); } else { log.error(e); return CommonUtil.getErrorResponse(ErrorToResponse.getJsonError(e.getMessage())); } } 
But instead of Russian, I get "?????? ??? ???". Already added :

 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> <property name="messageConverters"> <array> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg index="0" name="defaultCharset" value="UTF-8"/> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>application/x-www-form-urlencoded;charset=UTF-8</value> </list> </property> </bean> </bean> <bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"> <property name="messageConverters"> <array> <bean class="org.springframework.http.converter.StringHttpMessageConverter"> <constructor-arg index="0" name="defaultCharset" value="UTF-8"/> <property name="supportedMediaTypes"> <list> <value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>application/x-www-form-urlencoded;charset=UTF-8</value> </list> </property> </bean> </array> </property> </bean> 

But nothing helps! By the way in:

  @RequestMapping(value = "/Services/getData", method = RequestMethod.POST) @ResponseStatus(HttpStatus.OK) public ResponseEntity<String> getData(@RequestParam(value = "param", required = true) String param, HttpServletRequest request, HttpSession httpSession) { return execute(param, request, httpSession, CRUDServiceDAO.Action.GET); } 

Russian comes without problems, the problem only occurs in @ExceptionHandler (DataException.class) I really hope for your help !!!

    1 answer 1

    Well, I decided the question, not having time to ask. Maybe someone will come in handy. Added in

     <bean class="org.springframework.web.servlet.mvc.method.annotation.ExceptionHandlerExceptionResolver"> <property name="messageConverters"> <array> <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> <property name="supportedMediaTypes"> <list> value>text/plain;charset=UTF-8</value> <value>text/html;charset=UTF-8</value> <value>application/json;charset=UTF-8</value> <value>application/x-www-form-urlencoded;charset=UTF-8</value> </list> </property> </bean> ... 
    And the necessary dependencies in maven:

     <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.8.3</version> </dependency> 
    After that, I finally got the desired Russian language on the client.