Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/372.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java XmlBeans.Factory解析方法的ClassCastException不一致_Java_Tomcat_Heroku_Classcastexception_Xmlbeans - Fatal编程技术网

Java XmlBeans.Factory解析方法的ClassCastException不一致

Java XmlBeans.Factory解析方法的ClassCastException不一致,java,tomcat,heroku,classcastexception,xmlbeans,Java,Tomcat,Heroku,Classcastexception,Xmlbeans,我知道这是一个非常远大的目标,但我已经花了大约两周的时间试图解决这个问题,所以任何指向正确方向的想法都是无价的 因此,我有一个非常古老的应用程序,它使用XmlBeans。我的任务是从Tomcat 7.0.67迁移到Tomcat 8.5.11,引入Spring会话和Spring安全性,而不是基于领域的身份验证。在迁移之前,在本地(MacOS、Oracle JDK 8)和Heroku(Ubuntu、OpenJDK 8)上,一切都正常工作,但在迁移之后,一切都在我的本地环境下工作,但在Heroku上,

我知道这是一个非常远大的目标,但我已经花了大约两周的时间试图解决这个问题,所以任何指向正确方向的想法都是无价的

因此,我有一个非常古老的应用程序,它使用XmlBeans。我的任务是从Tomcat 7.0.67迁移到Tomcat 8.5.11,引入Spring会话和Spring安全性,而不是基于领域的身份验证。在迁移之前,在本地(MacOS、Oracle JDK 8)和Heroku(Ubuntu、OpenJDK 8)上,一切都正常工作,但在迁移之后,一切都在我的本地环境下工作,但在Heroku上,有时,当应用程序尝试将字符串解析为适当的XmlBean时,会出现以下ClassCastException:

java.lang.ClassCastException: foo.bar.2.impl.PreferencesDocumentImpl cannot be cast to foo.bar.1.PreferencesDocument
    at foo.bar.1.PreferencesDocument$Factory.parse(Unknown Source)
我有两个由XmlBeans自动生成的类,它们是由两个xsd模式生成的,没有任何名称空间集。类共享名称,但位于不同的包中(发生异常的解析方法位于工厂内部类中,省略了其他方法):

有时,当部署到Heroku的应用程序重新启动时,问题就消失了,但在再次重新启动后,问题又回来了

根据,根本原因是缺少名称空间,从而导致冲突。但由于我们的需求,我不能添加或更改XSD的名称空间。你知道为什么它在本地与Tomcat 7一起工作,在本地与Tomcat 8一起工作,在Heroku上与Tomcat 7一起工作,但在Heroku上与Tomcat 8不工作吗


提前感谢。

我怀疑问题的不可预测性(即,有时重启后会发生或不会发生)是由于JVM类加载器的不确定性造成的。如果同一类有两个不同的版本,它们将以不确定的顺序加载

在本例中,听起来您有两个同名的不同类(对吗?)。即使它们是自动生成的,也只有一个会赢


我认为您必须找到一种方法为类指定不同的名称(或包)。

我怀疑问题的不可预测性(即,有时重启后会发生或不会发生)是由于JVM类加载器的不确定性。如果同一类有两个不同的版本,它们将以不确定的顺序加载

在本例中,听起来您有两个同名的不同类(对吗?)。即使它们是自动生成的,也只有一个会赢


我认为您必须找到一种方法来为类指定不同的名称(或包)。

它在Tomcat7上工作,因为

在Tomcat 8之前,Tomcat的类加载器按字母顺序加载资源。正因为如此,我们的应用程序才起作用


它在Tomcat 8+MacOS上本地工作,因为Tomcat 8的类加载器按照OS提供的顺序加载资源,而在OSX中,似乎是按顺序加载的。

它在Tomcat 7上工作是因为

在Tomcat 8之前,Tomcat的类加载器按字母顺序加载资源。正因为如此,我们的应用程序才起作用


它在Tomcat 8+MacOS上本地工作,因为Tomcat 8的类加载器按照OS提供的顺序加载资源,在OSX的情况下,这种顺序似乎是有序的。

这些类确实有不同的包,只有名称相同,还有xsd命名空间(实际上没有)。这些类确实有不同的包,只有名称相同,以及xsd名称空间(实际上没有)。
/*
 * An XML document type.
 * Localname: Preferences
 * Namespace: 
 * Java type: foo.bar.1.PreferencesDocument
 *
 * Automatically generated - do not modify.
 */
package foo.bar.1;

public interface PreferencesDocument extends org.apache.xmlbeans.XmlObject {
    public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)
        org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(PreferencesDocument.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.s2D5798E4F4AFDA8394735C8512CDCBC7").resolveHandle("preferencesa8bfdoctype");

    public static final class Factory {
        public static foo.bar.1.PreferencesDocument parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
          return (foo.bar.PreferencesDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); 
        }   
    }
}

/*
 * An XML document type.
 * Localname: Preferences
 * Namespace: 
 * Java type: foo.bar.1.PreferencesDocument
 *
 * Automatically generated - do not modify.
 */
package foo.bar.1.impl;

public class PreferencesDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements foo.bar.1.PreferencesDocument {
    public PreferencesDocumentImpl(org.apache.xmlbeans.SchemaType sType) {
        super(sType);
    }

    private static final javax.xml.namespace.QName PREFERENCES$0 = new javax.xml.namespace.QName("", "Preferences");
}

/*
 * An XML document type.
 * Localname: Preferences
 * Namespace: 
 * Java type: foo.bar.2.PreferencesDocument
 *
 * Automatically generated - do not modify.
 */
package foo.bar.2;  

public interface PreferencesDocument extends org.apache.xmlbeans.XmlObject {
    public static final org.apache.xmlbeans.SchemaType type = (org.apache.xmlbeans.SchemaType)
        org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(PreferencesDocument.class.getClassLoader(), "schemaorg_apache_xmlbeans.system.sC8953008EC716AA258D3951B84AB1CB7").resolveHandle("preferencesa8bfdoctype");

    public static final class Factory {
        public static foo.bar.2.PreferencesDocument parse(java.lang.String xmlAsString) throws org.apache.xmlbeans.XmlException {
          return (foo.bar.2.PreferencesDocument) org.apache.xmlbeans.XmlBeans.getContextTypeLoader().parse( xmlAsString, type, null ); }

    }
}

/*
 * An XML document type.
 * Localname: Preferences
 * Namespace: 
 * Java type: foo.bar.2.PreferencesDocument
 *
 * Automatically generated - do not modify.
 */
package foo.bar.2.impl;

public class PreferencesDocumentImpl extends org.apache.xmlbeans.impl.values.XmlComplexContentImpl implements foo.bar.2.PreferencesDocument {

    public PreferencesDocumentImpl(org.apache.xmlbeans.SchemaType sType) {
        super(sType);
    }

    private static final javax.xml.namespace.QName PREFERENCES$0 = 
        new javax.xml.namespace.QName("", "Preferences");
    }
}