弹簧转换器 - 循环问题

时间:2011-01-03 23:52:30

标签: web-services spring-mvc jaxb jersey

我有一个问题,我有一个转换器类称为aConverter:

@XmlRootElement(name = "aConverter")
public class aConverter implements ConverterBase{

      private A a;
      private Set<B> bs;
      /// some constructor code here
      ...
      @XmlElement(name="B")
      public Set<B> getBs() {
                bs = a.getBs();
                return bs;
      }

      public void setBs(Set<B> bs) {
                a.setBs(bs);
      }
}

A类和B类分别以循环方式定义:

public class A {
       private Set <B> bs;

       //constructor code here
       ... 

       public Set<B> getBs() {
          return this.bs;
       }
       public void setBs(Set<B> bs) {
          this.bs = bs;
       }
}

&GT;

public class B {
       private A a;

       // some constructor code here
       ...

       public A getA() {
              return this.a;
       }
       public void setA(A a) {
              this.a = a;
       }
}

现在,当我在网络服务时,我看到以下错误:

[com.sun.istack.internal.SAXException2:在对象图中检测到一个循环。这将导致无限深的XML:B @ 1105452 - &gt; A @ 1 - &gt;乙@ 1105452]  在com.sun.jersey.core.provider.jaxb.AbstractRootElementProvider.writeTo(AbstractRootElementProvider.java:152)  at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:294)  at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1140)  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1053)  at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1043)  在com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:406)  在com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:477)  在com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)  在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)  在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)  在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  在org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)  在org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)  在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)  在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)  在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)  在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)  在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)  在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)  在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)  在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process(Http11Protocol.java:588)  在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)  在java.lang.Thread.run(Thread.java:680) 引起:javax.xml.bind.MarshalException   - 链接异常:

我真的没有想法,任何对此的反馈都会非常好。

干杯!

2 个答案:

答案 0 :(得分:1)

在EclipseLink JAXB(MOXy)中,我们引入了@XmlInverseReference扩展来解决这个问题。有关如何在JAX-RS服务中使用它的示例,请查看:

答案 1 :(得分:0)

您可以使用@XmlTransient注释。有关详情,请参阅this page