[英]JAXB com.sun.xml.internal.bind.v2.ContextFactory Class Not Found in JBoss AS 7
While using JAXB in JBoss, I am getting below exception while executing the code:在 JBoss 中使用 JAXB 时,我在执行代码时遇到以下异常:
JAXBContext jaxbContext = JAXBContext.newInstance( jaxbElement.getClass().getPackage().getName() );
Exception which i am getting is:我得到的例外是:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory from [Module "deployment.project.ear.subproject-jboss.jar:main" from Service Module Loader]]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:156) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:108) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:258) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:412) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:375) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:279) [jboss-jaxb-api_2.2_spec-1.0.4.Final-redhat-3.jar:1.0.4.Final-redhat-3]
It looks like JBoss JAXB module is loading instead of JDK and this is the reason of exception, however I am not sure how to solve this error?看起来 JBoss JAXB 模块正在加载而不是 JDK,这是异常的原因,但是我不知道如何解决这个错误?
Finally i solved it by changing default context factory to eclipse link context factory, but not sure why it does not worked with default one.最后,我通过将默认上下文工厂更改为 eclipse 链接上下文工厂来解决它,但不确定为什么它不适用于默认上下文工厂。
JAXBContext jaxbContext = JAXBContextFactory.createContext( clss.getPackage().getName() , clss.getClass().getClassLoader());
and by importing org.eclipse.persistence.jaxb.JAXBContextFactory
class.并通过导入
org.eclipse.persistence.jaxb.JAXBContextFactory
类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.