konfigurieren der jacksonObjectMapper nicht in spring mvc 3
Was ich bin mit dem Ziel zu tun, ist die Konfiguration von spring mvc 3 nicht zurückkehren "null" - Objekt in json-Antwort.
Ich habe gefragt, die Frage wie zu konfigurieren, spring mvc 3, um nicht wieder von "null" - Objekt in json-response? . Und der Vorschlag, den ich habe ist die Konfiguration der ObjectMapper, Einstellung der Serialisierung Eingliederung JsonSerialize.Einbeziehung.NON_NULL. Also Basierend auf Frühjahr konfigurieren @ResponseBody JSON-format, ich habe die folgenden änderungen in der spring config-Datei. Aber ich habe den Fehler "Abgelehnt bean name 'jacksonObjectMapper': keine URL-Pfade identifiziert org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping:86-AbstractDetectingUrlHandlerMapping.java" während der app-Start.
<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />
<!-- Forwards requests to the "/" resource to the "welcome" view -->
<!--<mvc:view-controller path="/" view-name="welcome"/>-->
<!-- Configures Handler Interceptors -->
<mvc:interceptors>
<!-- Changes the locale when a 'locale' request parameter is sent; e.g. /?locale=de -->
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />
</mvc:interceptors>
<!-- Saves a locale change using a cookie -->
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.CookieLocaleResolver" />
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter">
<property name="objectMapper" ref="jacksonObjectMapper" />
</bean>
</list>
</property>
</bean>
<bean id="jacksonObjectMapper" class="org.codehaus.jackson.map.ObjectMapper" />
<bean id="jacksonSerializationConfig" class="org.codehaus.jackson.map.SerializationConfig"
factory-bean="jacksonObjectMapper" factory-method="getSerializationConfig" />
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="jacksonSerializationConfig" />
<property name="targetMethod" value="setSerializationInclusion" />
<property name="arguments">
<list>
<value type="org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion">NON_DEFAULT</value>
</list>
</property>
</bean>
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
Ich habe keine Ahnung, warum es abgelehnt wurde. Jede Anregung ist sehr willkommen!
Du musst angemeldet sein, um einen Kommentar abzugeben.
<mvc:annotation-driven />
undAnnotationMethodHandlerAdapter
können nicht zusammen verwendet werden. (ref: Frühlings-Forums-thread). Mögliche Lösungnicht verwenden
<mvc:annotation-driven/>
. Deklarieren bean:DefaultAnnotationHandlerMapping
und
AnnotationMethodHandlerAdapter
und andere Einstellungen wie Validierung, Formatierung.verwenden, spring 3.1, die
<mvc:message-converters>
(ref: Spring jira)<mvc:message-converters>
element.