MappingJacksonHttpMessageConverter의 기본 objectMapper를 바꾸고 싶습니다. MappingJacksonHttpMessageConverter의 기본 objectMapper를 변경하는 방법은 무엇입니까?
내가 일하는 해결책을 발견하지만 난 그것에 대해 행복하지 않다 :<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<!-- Scans the classpath of this application for @Components to deploy as beans -->
<context:component-scan base-package="org.mypackage.service"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="messageConverters">
<list>
<!--Adding the default message converters-->
<bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="writeAcceptCharset" value="false"/>
</bean>
<bean class="org.springframework.http.converter.xml.SourceHttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.XmlAwareFormHttpMessageConverter"/>
<!--Adding our custom JSON converter-->
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper">
<util:constant static-field="org.mypackage.JsonUtils.MAPPER"/>
</property>
</bean>
</list>
</property>
</bean>
이 솔루션은 메시지 컨버터의 내 사용자 지정 목록 RequestMappingHandlerAdapter 클래스를 초기화합니다.
기본 메시지 변환기 (org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter
생성자에서 복사 한 내용)를 추가해야하므로이 솔루션이 마음에 들지 않습니다.
기본 변환기를 추가하지 않고도 컨트롤러에서 application/json 요청 만 처리하고 application/xml과 같은 다른 기본 요청을 처리하는 방법을 잊어 버릴 수있었습니다.
감사합니다.
은 3.1.0 버전 이후에 작동하지 않습니다. AnnotationMethodHandlerAdapter가 RequestMappingHandlerAdapter로 바뀌었기 때문입니다. – vacuum