大佬教程收集整理的这篇文章主要介绍了配置jacksonObjectMapper在Spring MVC 3中不起作用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<mvc:Annotation-driven
/>
并且AnnotationMethodHandlerAdapter
不能一起使用。(参考:spring论坛主题)。可能的解决方案
不要使用<mvc:Annotation-driven/>
。声明bean:DefaultAnnotationHandlerMapPing
和AnnotationMethodHandlerAdapter
其他设置,如验证,格式化。
使用spring 3.1,它具有<mvc:message-converters>
(ref:Spring jira)
我的目标是将spring mvc 3配置为在json响应中不返回“ null”对象。我问过一个问题,如何配置SpringMVC3在JSON响应中不返回“空”对象?。我得到的建议是配置ObjectMapper,将序列化包含设置为Jsonserialize.Inclusion.NON_NULL。因此,基于Spring
configure @ResponseBodyJSON格式,我在spring配置文件中做了以下更改。但是我在应用程序启动期间收到错误消息“拒绝的bean名称’jacksonObjectMapper’:没有URL路径标识为org.springframework.web.servlet.mvc.Annotation.DefaultAnnotationHandlerMapping:86-AbstractDetecTingUrlHandlerMapping.java”。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/scheR_890_11845@a/beans"
xmlns:xsi="http://www.w3.org/2001/XMLscheR_890_11845@a-instance"
xmlns:mvc="http://www.springframework.org/scheR_890_11845@a/mvc"
xsi:scheR_890_11845@aLOCATIOn="
http://www.springframework.org/scheR_890_11845@a/beans http://www.springframework.org/scheR_890_11845@a/beans/spring-beans-3.0.xsd
http://www.springframework.org/scheR_890_11845@a/mvc http://www.springframework.org/scheR_890_11845@a/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>
我不知道为什么它被拒绝了。任何建议,不胜感激!
以上是大佬教程为你收集整理的配置jacksonObjectMapper在Spring MVC 3中不起作用全部内容,希望文章能够帮你解决配置jacksonObjectMapper在Spring MVC 3中不起作用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。