设置要使用的JAXB上下文工厂初始化类 [英] Set the JAXB context factory initialization class to be used

查看:736
本文介绍了设置要使用的JAXB上下文工厂初始化类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经更新了我们的项目(基于Java EE,在Websphere 8.5上运行),以使用公司内部框架的新版本(以及Ejb 3.x部署描述符而不是2.x部署描述符)。从那时起,我的集成测试失败,出现以下异常:

I have updated our projects (Java EE based running on Websphere 8.5) to use a new release of a company internal framework (and Ejb 3.x deployment descriptors rather than the 2.x ones). Since then my integration Tests fail with the following exception:

 [java.lang.ClassNotFoundException: com.ibm.xml.xlxp2.jaxb.JAXBContextFactory]

我可以使用之前的框架版本构建应用程序,一切正常。
调试时我注意到在ContextFinder(javax.xml.bind)中有两种不同的行为:

I can build the application with the previous framework release and everything works fine. While debugging i noticed that within the ContextFinder (javax.xml.bind) there are two different behaviours:


  1. 以前的版本(一切正常):不同的地方都没有出现工厂类,因此加载了默认的工厂类,即com.sun.xml.internal.bind.v2.ContextFactory(在类中定义为String常量) 。

  1. Previous Version (Everything works just fine): None of the different places brings up a factory class so the default factory class gets loaded which is com.sun.xml.internal.bind.v2.ContextFactory (defined as String constant within the class).

升级版本(ClassNotFound):有一个资源META-INF / services / javax.xml.bind.JAXBContext成功加载并且第一个line read使ContextFinder尝试加载导致错误的com.ibm.xml.xlxp2.jaxb.JAXBContextFactory。

Upgraded Version (ClassNotFound): There is a resource "META-INF/services/javax.xml.bind.JAXBContext" beeing loaded successfully and the first line read makes the ContextFinder attempt to load "com.ibm.xml.xlxp2.jaxb.JAXBContextFactory" which causes the error.

我现在有两个问题:


  1. 该资源是什么类型的?因为在我们的EAR中有两个WAR,并且这两个WAR中没有一个在
    META-INF目录中包含文件夹服务。

  1. What sort is that resource? Because inside our EAR there is two WARs and none of those two contains a folder services in its META-INF directory.

这个值可以在哪里来自其他地方?因为一个档案室向我显示没有新的或更改的属性文件。

Where could that value be from otherwise? Because a filediff showed me no new or changed properties files.

无需说我将阅读所有关于JAXB配置的可能性,但如果您对可能出现的问题有所了解或帮助我使用该资源(这是一个我需要查找的真实文件吗?)id非常感谢。非常感谢!

No need to say i am going to read all about the JAXB configuration possibilities but if you have first insights on what could have gone wrong or help me out with that resource (is it a real file i have to look for?) id appreciate a lot. Many Thanks!

编辑(根据评论输入/问题):


出于好奇,您的框架是否包含JAXB JAR?您的框架的旧版本是否包含jaxb.properties?

确实(我有点惊讶)框架已经EAR内部定制的eclipselink-2.4.1-.jar,包括JAXB实现和jaxb.properties文件,该文件在两个版本中显示以下条目(查找工厂以及抛出异常的版本) ):

Indeed (i am a bit surprised) the framework has a customized eclipselink-2.4.1-.jar inside the EAR that includes both a JAXB implementation and a jaxb.properties file that shows the following entry in both versions (the one that finds the factory as well as in the one that throws the exception):

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

我认为这与当前问题无关,因为jar在两个EAR中都保持完全相同(那个运行/带有预期的那个)

I think this is has nothing to do with the current issue since the jar stayed exactly the same in both EARs (the one that runs/ the one with the expection)


我也不清楚为什么旧版本的框架选择了com.sun实现

有一个类javax.xml.bind.ContextFinder,它负责初始化JAXBContextFactory。此类搜索各种访问以查找jaxb.properties文件或javax.xml.bind.JAXBContext资源的存在。如果所有这些地方都没有显示要使用哪个Context Factory,那么会加载一个在类本身中硬编码的deault工厂:

There is a class javax.xml.bind.ContextFinder which is responsible for initializing the JAXBContextFactory. This class searches various placess for the existance of a jaxb.properties file or a "javax.xml.bind.JAXBContext" resource. If ALL of those places dont show up which Context Factory to use there is a deault factory loaded which is hardcoded in the class itself:

private static final String PLATFORM_DEFAULT_FACTORY_CLASS = "com.sun.xml.internal.bind.v2.ContextFactory";

现在回到我的问题:

使用以前版本的框架(以及EJB 2.x部署描述符)构建一切正常)。在调试时我可以看到没有找到配置,因此上面提到了默认工厂。

Building with the previous version of the framework (and EJB 2.x deployment descriptors) everything works fine). While debugging i can see that there is no configuration found and thatfore above mentioned default factory is loaded.

使用新版本的框架构建(和EJB 3.x部署)描述符,所以我可以部署)只有一个TESTCASE失败,但其余的功能工作(就像我可以发送请求到我们的Web服务,他们不会触发任何错误)。调试时我可以看到找到了配置。该资源名为META-INF / services / javax.xml.bind.JAXBContext。以下是此资源如何导致尝试加载com.ibm.xml.xlxp2.jaxb.JAXBContextFactory然后抛出ClassNotFoundException的最重要的部分。这是上述javax.xml.bind.ContextFinder类的简化源:

Building with the new version of the framework (and EJB 3.x deployment descriptors so i can deploy) ONLY A TESTCASE fails but the rest of the functionality works (like i can send requests to our webservice and they dont trigger any errors). While debugging i can see that there is a configuration found. This resource is named "META-INF/services/javax.xml.bind.JAXBContext". Here are the most important lines of how this resource leads to the attempt to load 'com.ibm.xml.xlxp2.jaxb.JAXBContextFactory' which then throws the ClassNotFoundException. This is simplified source of the mentioned javax.xml.bind.ContextFinder class:

URL resourceURL = ClassLoader.getSystemResource("META-INF/services/javax.xml.bind.JAXBContext");

BufferedReader r = new BufferedReader(new InputStreamReader(resourceURL.openStream(), "UTF-8"));

String factoryClassName = r.readLine().trim();  

字段factoryClassName现在的值为'com.ibm.xml.xlxp2.jaxb.JAXBContextFactory'

The field factoryClassName now has the value 'com.ibm.xml.xlxp2.jaxb.JAXBContextFactory'

因为这已经成为一个超级大问题我还会添加一个赏金:)
我将在这整天工作并让你知道是否有任何新闻。

Because this has become a super lager question i will also add a bounty :) I will work the entire day on this and let you know if there is any news.

更新/解决方案

此问题已解决。原始问题已经发生,因为错误配置了复杂构建的多模型maven项目,其中一个依赖项使用了自定义eclipse链接jar的更新版本,其中包含发生错误的组件中不可用的JAXBFactory的定义。在大多数情况下,设置JAXB上下文工厂是使用包含相同定义的jaxb.propertie文件或JAXBContext文件配置的。适当的JAXBContextFactory的详细加载过程发生在javax.xml.bind.ContextFinder中。

This question has been solved. The original problem has occured because misconfiguration of complexly build multi model maven projects which one dependency used a updated version of a customized eclipse link jar that contained a definition for a JAXBFactory not available in the component where the error occured. Setting the JAXB context factory in most cases is configured with a jaxb.propertie file or JAXBContext file that contains the same definition. Detailed loading process of the appropriate JAXBContextFactory happens in javax.xml.bind.ContextFinder.

错误尚未解决(在4个主要EE / SE应用程序导致错误的情况下)并且没有一般答案但是定义的JAXBContextFactorys必须存在在你的类路径中(哇多么奇怪...)所以你要么有一个ClassNotFound错误,因为你缺少资源(这就是实际原因),或者因为你在上面提到的任何属性文件中定义了一个错误的JAXBContextFactory根据以下答案定义。

The error has not yet been solved (during the fact over 4 major EE/SE Applications lead to the error) and there is no general answer but that defined JAXBContextFactorys must exist in your classpath (wow what a wonder...) so you either have a that ClassNotFound Error because youre missing resources (well thats the acctual cause) or because you have a wrong JAXBContextFactory defined in any of the above mentioned propertie files which contain a definition according to the below answer.

非常感谢您的好评和支持,我真的很感激!

Very many thanks for your great comments and support, i realy appreciate!

推荐答案

您可以在与域模型相同的包中包含 jaxb.properties 文件,以指定JAXB( JSR-222 )您希望使用的实现。例如,它将如下所示指定 EclipseLink MOXy 作为您的JAXB提供者。

You can include a jaxb.properties file in the same package as your domain model to specify the JAXB (JSR-222) implementation you wish to use. For example it would look like the following to specify EclipseLink MOXy as your JAXB provider.

javax.xml.bind.context.factory=org.eclipse.persistence.jaxb.JAXBContextFactory

更多信息

  • http://blog.bdoughan.com/2011/05/specifying-eclipselink-moxy-as-your.html

这篇关于设置要使用的JAXB上下文工厂初始化类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆