Tomcat,JAXB在JSP应用程序中进行编组:添加模式会引发异常

时间:2011-03-14 15:08:59

标签: xml tomcat xsd jaxb marshalling

对于使用XML作为导出/导入格式的大型项目,我收到了一个XSD架构文件。我使用JAXB生成类,添加例程以将数据填充到生成的类中。现在我将整个文件编组到磁盘上的XML文件中:

Spmigration mig = new Spmigration(); //Main migration object
mig.setBestellungen(new OrdersImpl().getOrders(shop));
JAXBContext jc = JAXBContext.newInstance( "my.migration.context" );
Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal( mig, new File("test.xml") );

这就像一个魅力。输出文件格式正确,并且给定正确的模式,甚至是有效的。现在,我正在尝试导出文件,但直接添加架构。我添加了几行:

Spmigration mig = new Spmigration(); //Main migration object
mig.setBestellungen(new OrdersImpl().getOrders(shop));
JAXBContext jc = JAXBContext.newInstance( "my.migration.context" );
Marshaller m = jc.createMarshaller();
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
Schema schema = schemaFactory.newSchema(new File("myschema.xsd"));
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.setSchema(schema);
m.marshal( mig, new File("test.xml") );

模式文件存在且可读(我知道因为当我第一次尝试时忘记提供文件时出现了另一个错误)。现在,行

Schema schema = schemaFactory.newSchema(new File("myschema.xsd"));

生成以下异常:

  

java.lang.VerifyError :(类:org / apache / xerces / impl / xs / XSAnnotationImpl,方法:writeToDOM签名:(Lorg / w3c / dom / Node; S)V)函数调用的不兼容对象参数       org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)

当然,这不是整个堆栈跟踪。但似乎是问题所在。我没有从网络知道的这个特定错误消息的极少数问题中读到任何重要内容。

有什么我可以检查的,我做错了什么吗?

1 个答案:

答案 0 :(得分:0)

这不是一个真正的解决方案,但我们最终做的并不是使用为此描述的方法添加架构,而是稍后通过文本替换添加架构。