Spring OXM 3 + JiBXException:没有为类定义marshaller

时间:2012-06-20 14:01:11

标签: spring-ws spring-3 jibx spring-oxm

我在我的应用程序中使用了Spring OXM和JiBX。

下面的

是我的Spring配置文件

<context:component-scan base-package="com.controller"/>

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>

<oxm:jibx-marshaller target-class="com.request.RequestClass" id="rqMarshaller"/>
<oxm:jibx-marshaller target-class="com.response.ResponseClass" id="rsMarshaller"/>

<bean id="xmlViewer" class="org.springframework.web.servlet.view.xml.MarshallingView">
    <constructor-arg ref="rsMarshaller" />
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver"/>

以下是控制器类

@Controller
public class MyController {
    @Autowired
    private JibxMarshaller rqMarshaller;

    @RequestMapping(value = "/myrequest", method = RequestMethod.POST)
    public ModelAndView searchFlights(@RequestBody String request) {
        System.out.println("Inside");
        System.out.println("request = "+request);
        Source source = new StreamSource(new StringReader(request));

        RequestClass rq = null;
        try {
            rq = (RequestClass) rqMarshaller.unmarshal(source);
        } catch (XmlMappingException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

        ResponseClass e = new ResponseClass();
        e.setVersion("2.0");

        Orig ond = new Orig();
        ond.setCode("AIT");

        e.getOrig().add(ond);
        return new ModelAndView("xmlViewer","object",e);
    }
}

当我发送XML请求时,它已成功编组,但对于响应,我收到了以下错误消息。

org.jibx.runtime.JiBXException: No marshaller defined for class com.response.ResponseClass

我已经在spring配置文件中为ResponseClass定义了marshaller。

请帮忙。感谢。

1 个答案:

答案 0 :(得分:0)

最后我想出了解决方案!!!

注册bindingName时需要指定JiBxMarshaller属性。

<oxm:jibx-marshaller target-class="com.request.RequestClass" id="rqMarshaller" bindingName="rqBinding"/>
<oxm:jibx-marshaller target-class="com.response.ResponseClass" id="rsMarshaller" bindingName="rsBinding/>

并在JiBX的相应绑定/映射文件中指定相同的名称。

就是这样!