安全处理 org.xml.sax.SAXNotRecognizedException 导致 java.lang.IllegalStateException 在 Tomcat 中运行的解决方案

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23952888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 09:22:50  来源:igfitidea点击:

Solution for secure-processing org.xml.sax.SAXNotRecognizedException causing java.lang.IllegalStateException running inside Tomcat

javaxml

提问by Javier Mr

I'm facing this exception when receiving an Xml and trying to parse it. The code responsible for that is well tested when running as an standalone application. However I'm now integrating it in Tomcat.

我在接收 Xml 并尝试解析它时遇到了这个异常。当作为独立应用程序运行时,负责该任务的代码已经过充分测试。但是我现在将它集成到 Tomcat 中。

The stack trace is:

堆栈跟踪是:

java.lang.IllegalStateException: org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing
    at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:121)
    at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getXMLReader(UnmarshallerImpl.java:139)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:204)

Digging around I found this, so maybe the solution is to change the options Tomcat sets.

挖掘周围我发现了这一点,所以也许解决方案是更改 Tomcat 设置的选项。

So the question is:

所以问题是:

  • Which is the problem's root?
  • Best way to solve it?
  • Is a good approach to change Tomcat options? how is this done?
  • 问题的根源在哪里?
  • 最好的解决方法?
  • 是更改 Tomcat 选项的好方法吗?这是怎么做的?

Update

更新

This happens when running it with Java 8, reverting to Java 7 works ok.

使用 Java 8 运行它时会发生这种情况,恢复到 Java 7 工作正常。

回答by user2974606

I had faced similar issue, this issue occurs when there is big difference in versions of xerces jar and xercesImpl jar. To solve this, I used xerces-2.9.0 and xercesImpl-2.9.1 and the issue gone.

我遇到过类似的问题,当 xerces jar 和 xercesImpl jar 的版本存在很大差异时会出现此问题。为了解决这个问题,我使用了 xerces-2.9.0 和 xercesImpl-2.9.1 并且问题消失了。

回答by Nayan Sonthalia

I know this is an old question. But just updating it if it is of any help to others.. We had a similar issue recently while upgradig to java 8 with JBOSS 3.2.6. The cause of the issue was an old xercesImpl.jar. We upgraded to xercesImol-2.9.1.jar and the issue was resolved.

我知道这是一个老问题。但是如果对其他人有帮助,就更新它。最近我们在使用 JBOSS 3.2.6 升级到 java 8 时遇到了类似的问题。问题的原因是旧的 xercesImpl.jar。我们升级到 xercesImol-2.9.1.jar 并解决了问题。

回答by Aakash Patel

Well, this worked for me: Added below to my tomcat configuration arguments: -Djavax.xml.parsers.SAXParserFactory="com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"

嗯,这对我有用:在下面添加到我的 tomcat 配置参数: -Djavax.xml.parsers.SAXParserFactory="com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl"