JSP 应用程序中的 Tomcat、JAXB 编组:添加架构会引发异常
对于使用 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)
当然,这不是整个堆栈跟踪。但这似乎是问题所在。我没有从网络上通过此特定错误消息了解的极少数问题中读到任何重要信息。
有什么我可以检查的吗?我做错了什么吗?
For a larger project using XML as an export/import format, I recieved an XSD schema file. I used JAXB to generate the classes, added routines to fill the data into the generated classes. Now I am marshalling the whole file into an XML file on disk:
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") );
This works like a charm. The output file is well-formed and, given the right schema, even valid. Now, I am trying to export the file, but adding the schema directly. I added a few lines:
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") );
The schema file exists and is readable (I know because I got another error when I forgot to supply the file when I first tried). Now, the line
Schema schema = schemaFactory.newSchema(new File("myschema.xsd"));
generated the following exception:
java.lang.VerifyError: (class: org/apache/xerces/impl/xs/XSAnnotationImpl, method: writeToDOM signature: (Lorg/w3c/dom/Node;S)V) Incompatible object argument for function call
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:862)
Of course, this is not the whole stack trace. But it seems to be the problem. I'm not reading anything significant from the very low number of problems that the net knows about with this specific error message.
Is there anything I could check, anything I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这并不是真正的解决方案,但我们最终所做的不是使用为此描述的方法添加模式,而是稍后在另一个步骤中通过文本替换添加模式。
It's not really a solution, but what we finally did was not add the schema using the methods described for that, but add the schema later via a textual replace in another step.