Error unmarshalling xml in java-8 quot;secure-processing org.xml.sax.SAXNotRecognizedException causing java.lang.IllegalStateExceptionquot;(在 java-8 “secure-processing org.xml.sax.SAXNotRecognizedException 导致 java.lang.IllegalStateException中解组 xml 时出错)
问题描述
以下代码在 Java 7 中运行良好
The following code worked fine in Java 7
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
String xmlString = '<xml ..... ';
StringReader reader = new StringReader(xmlString);
JAXBContext jc = JAXBContext.newInstance(MyClass.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
MyClass myClass = (MyClass) unmarshaller.unmarshal(reader);
....
现在我们必须升级到 Java 8,现在执行代码时出现此异常:
Now we had to upgrade to Java 8 and now I get this exception when executing the code:
Sep 03, 2014 1:42:47 PM com.sun.xml.internal.bind.v2.util.XmlFactory createParserFactory
SCHWERWIEGEND: null
org.xml.sax.SAXNotRecognizedException: Feature: http://javax.xml.XMLConstants/feature/secure-processing
at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(SAXParserFactoryImpl.java:100)
at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:114)
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:214)
我知道有一个问题 针对类似的问题,但退回到 java 7 对我来说不是解决方案.
I know that there is a question targeting a similar problem, but stepping back to java 7 is not a solution for me.
我尝试添加以下maven依赖
I tried to add the following maven dependency
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4</version>
</dependency>
但这并没有改变结果,所以我删除了它(感谢@BlaiseDoughan 提供的信息,它包含在 Java 6 中)
but that did not change the result, so I removed it (thanks to @BlaiseDoughan for the information, that this is included in Java 6)
欢迎任何提示,非常感谢.
Any hints are welcome, many thanks.
推荐答案
这是一个依赖问题.
这是我解决问题的方法:
Here is my way how I solved the problem:
- 创建一个新的 maven 项目,使用我在下面附加的那段简单的代码,程序正常崩溃并出现错误,无法解析结构,这没关系.
将你的依赖项复制到项目 pom.xml 中,现在程序应该会崩溃(如上所述)
- Make a new maven project, with that simple pieces of code, I attached below, the programm crashed normally with an error, that the structure couldn't be parsed which is ok.
Copy your dependencies into the project pom.xml, now the programm should crash (as described above)
不,你在你喜欢的方法(好猜测,Bisection,1-by-1 ..)之后删除依赖项以找到坏"依赖项.也许有人有更好(更专业)的方法,这个对我有用.
no you remove dependencies after your favoured method (good guessing, Bisection , 1-by-1 ..) to find the "bad" dependency. Maybe someone has a better (more professional) method, this one worked for me.
现在你可以决定要做什么了,也许有新版本可用,在我们的例子中,它是一个学院的自己的包,他包含一个学院的包,我可以排除.
now you can descide what to do, maybe a new version is available, in our case it was out own package of a colleage, where he included a package of a colleage, which i could exclude.
public class Test {
public Test() {
}
public static void main(String[] args) {
try {
StringReader reader = new StringReader("<xml></xml>");
JAXBContext jc = JAXBContext.newInstance(TestXML.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
TestXML testXMLs = (TestXML) unmarshaller.unmarshal(reader);
} catch (JAXBException e) {
e.printStackTrace();
}
}
}
和 testXML 类
and the testXML class
@XmlRootElement(name="rss")
@XmlAccessorType(XmlAccessType.FIELD)
public class TestXML {
public TestXML() {
}
@XmlElementWrapper(name="channel")
@XmlElement(name="item")
private int i ;
public int getI() {
return i;
}
public void setI(int i) {
this.i = i;
}
}
顺便说一句:在我的情况下是
BTW: In my case it was
<dependency>
<groupId>jcs</groupId>
<artifactId>jcs</artifactId>
<version>1.3</version>
</dependency>
希望对您有所帮助.
这篇关于在 java-8 “secure-processing org.xml.sax.SAXNotRecognizedException 导致 java.lang.IllegalStateException"中解组 xml 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 java-8 “secure-processing org.xml.sax.SAXNotRecognizedE


基础教程推荐
- 如何使用 Stream 在集合中拆分奇数和偶数以及两者的总和 2022-01-01
- Spring Boot Freemarker从2.2.0升级失败 2022-01-01
- 由于对所需库 rt.jar 的限制,对类的访问限制? 2022-01-01
- 如何在不安装整个 WTP 包的情况下将 Tomcat 8 添加到 Eclipse Kepler 2022-01-01
- 在螺旋中写一个字符串 2022-01-01
- 首次使用 Hadoop,MapReduce Job 不运行 Reduce Phase 2022-01-01
- Java 中保存最后 N 个元素的大小受限队列 2022-01-01
- 如何对 HashSet 进行排序? 2022-01-01
- 如何强制对超级方法进行多态调用? 2022-01-01
- 如何使用 Eclipse 检查调试符号状态? 2022-01-01