Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MVC-在使用@ResponseBy时设置JAXB封送器属性_Java_Spring_Spring Mvc_Jaxb_Moxy - Fatal编程技术网

Java Spring MVC-在使用@ResponseBy时设置JAXB封送器属性

Java Spring MVC-在使用@ResponseBy时设置JAXB封送器属性,java,spring,spring-mvc,jaxb,moxy,Java,Spring,Spring Mvc,Jaxb,Moxy,我试图从我的控制器返回一个对象,该对象应该由spring解析为xml。 但是我在类中使用了fromMoxy eclipselink注释来定制返回的对象。因此,我必须从marshaller设置属性MarshallerProperties.OBJECT_图 在我的控制器中,我如何访问marshaller,spring使用它来解析我的对象 即: 提前感谢您的帮助。如果您需要自定义封送拆收器,创建封送拆收视图并使用所需的属性配置封送拆收器,这是配置JAXB封送拆收器的示例请参见: 如果需要自定义封送拆收

我试图从我的控制器返回一个对象,该对象应该由spring解析为xml。 但是我在类中使用了fromMoxy eclipselink注释来定制返回的对象。因此,我必须从marshaller设置属性MarshallerProperties.OBJECT_图

在我的控制器中,我如何访问marshaller,spring使用它来解析我的对象

即:


提前感谢您的帮助。

如果您需要自定义封送拆收器,创建封送拆收视图并使用所需的属性配置封送拆收器,这是配置JAXB封送拆收器的示例请参见:


如果需要自定义封送拆收器、创建封送拆收视图并使用所需的属性配置封送拆收器,这是配置JAXB封送拆收器的示例请参见:


您需要实现自己的AbstractJaxb2HttpMessageConverter类并重写其createMarshaller方法,以提供具有自己属性的封送拆收器。查看Jaxb2RootElementHttpMessageConverter以获取实现提示

一旦实现了这样一个类,就需要将其注册为MVC堆栈中的HttpMessageConverter。如果您是通过Java进行配置,请查看WebMvcConfigurationSupportconfigureMessageConverters。。。如果您是通过XML实现的,请查看

<mvc:annotation-driven>
    <mvc:message-converters>
        <!-- bean goes here -->
    </mvc:message-converters>
</mvc:annotation-driven>

您需要实现自己的AbstractJaxb2HttpMessageConverter类并重写其createMarshaller方法,以提供具有自己属性的封送拆收器。查看Jaxb2RootElementHttpMessageConverter以获取实现提示

一旦实现了这样一个类,就需要将其注册为MVC堆栈中的HttpMessageConverter。如果您是通过Java进行配置,请查看WebMvcConfigurationSupportconfigureMessageConverters。。。如果您是通过XML实现的,请查看

<mvc:annotation-driven>
    <mvc:message-converters>
        <!-- bean goes here -->
    </mvc:message-converters>
</mvc:annotation-driven>

就像索蒂里奥斯·德里马诺利斯所说的那样。您必须实现自己的AbstractJaxb2HttpMessageConverter。除此之外,您还实现了WebBindingInitializer并将其注册到:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="com.example.CommonWebBindingInitializer" />
    </property>
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
            <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
            <bean class="com.example.Jaxb2RootElementHttpMessageConverter" />
        </list>
    </property>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

就像索蒂里奥斯·德里马诺利斯所说的那样。您必须实现自己的AbstractJaxb2HttpMessageConverter。除此之外,您还实现了WebBindingInitializer并将其注册到:

<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
    <property name="webBindingInitializer">
        <bean class="com.example.CommonWebBindingInitializer" />
    </property>
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter" />
            <bean class="org.springframework.http.converter.StringHttpMessageConverter" />
            <bean class="org.springframework.http.converter.ResourceHttpMessageConverter" />
            <bean class="com.example.Jaxb2RootElementHttpMessageConverter" />
        </list>
    </property>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />

这是引导Spring的老方法。这两个bean类都已弃用。您需要WebBindingInitializer做什么?这是引导Spring的老方法。这两个bean类都已弃用。您需要WebBindingInitializer做什么?