jaxb2 SAXParseException: 发现无效内容

jaxb2 SAXParseException: Invalid content was found

我正在使用 spring.oxm 和带有 SAX 解析器的 jaxb2 将 java 对象编组到 xml。

我 运行 遇到问题,我的编组器抛出一个 org.xml.sax.SAXParseException 说明有:

Invalid content was found starting with element 'ns59:ArtID'. One of {[...],http://www.bipro.net/namespace/gevo":ArtID, [...]} is expected.

在我的 org.springframework.oxm.jaxb.JAXBMarshaller.graph 中似乎一切正常,至少在我看来是这样。 该图显示了调试模式下的这些变量: 这是 jaxax.xml.transform.result.writer 在因错误而中断并留下如下输出字符串之前:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <ns43:getShipmentResponse 
xmlns="http://www.bipro.net/namespace/basis" 
xmlns:ns2="http://www.bipro.net/namespace/nachrichten" 
xmlns:ns3="http://www.bipro.net/namespace/abrechnung" 
xmlns:ns4="http://www.bipro.net/namespace/allgemein" 
xmlns:ns5="http://www.bipro.net/namespace/schaden-leistung" 
xmlns:ns6="http://www.bipro.net/namespace/partner" 
xmlns:ns7="http://www.bipro.net/namespace/sachen" 
xmlns:ns8="http://www.bipro.net/namespace/versicherung/produktmodell/rechtsschutz" 
xmlns:ns9="http://www.bipro.net/namespace/produktmodell" 
xmlns:ns10="http://www.bipro.net/namespace/versicherung/produktmodell" 
xmlns:ns11="http://www.bipro.net/namespace/kapitalanlage/basis" 
xmlns:ns12="http://www.bipro.net/namespace/versicherung/produktmodell/komposit" 
xmlns:ns13="http://www.bipro.net/namespace/kapitalanlage/transaktion" 
xmlns:ns14="http://www.bipro.net/namespace/provision" 
xmlns:ns15="http://www.bipro.net/namespace/beteiligungsverhaeltnis" 
xmlns:ns16="http://www.bipro.net/namespace/kapitalanlage" 
xmlns:ns17="http://www.bipro.net/namespace/versicherung/produktmodell/kraftfahrt" 
xmlns:ns18="http://www.bipro.net/namespace/fragen" 
xmlns:ns19="http://www.bipro.net/namespace/versicherung/produktmodell/kranken" 
xmlns:ns20="http://www.bipro.net/namespace/vertrag" 
xmlns:ns21="http://www.bipro.net/namespace/foerderung" 
xmlns:ns22="http://www.bipro.net/namespace/versicherung/produktmodell/leben" 
xmlns:ns23="http://www.bipro.net/namespace/versicherung/unfall" 
xmlns:ns24="http://www.bipro.net/namespace/sepa" 
xmlns:ns25="http://www.bipro.net/namespace/versicherung/haftpflicht" 
xmlns:ns26="http://www.bipro.net/namespace/schaden-objekte" 
xmlns:ns27="http://www.bipro.net/namespace/schaden-details" 
xmlns:ns28="http://www.bipro.net/namespace/versicherung/sach" 
xmlns:ns29="http://www.bipro.net/namespace/fahrzeug"
xmlns:ns30="http://www.bipro.net/namespace/gevo" 
xmlns:ns32="http://www.bipro.net/namespace/evb" 
xmlns:ns33="http://www.bipro.net/namespace/prozesse/foerderdaten" 
xmlns:ns34="http://www.bipro.net/namespace/prozesse/partner" 
xmlns:ns35="http://www.bipro.net/namespace/prozesse/schaden" 
xmlns:ns36="http://www.bipro.net/namespace/prozesse/vertrag" 
xmlns:ns37="http://www.bipro.net/namespace/prozesse/versicherung/vertrag/komposit" 
xmlns:ns38="http://www.bipro.net/namespace/prozesse/versicherung/vertrag/kraftfahrt" 
xmlns:ns39="http://www.bipro.net/namespace/prozesse/versicherung/vertrag/kranken" 
xmlns:ns40="http://www.bipro.net/namespace/prozesse/versicherung/vertrag/leben" 
xmlns:ns41="http://www.bipro.net/namespace/versicherung/tarifierung" 
xmlns:ns42="http://www.bipro.net/namespace/tools/iban" 
xmlns:ns43="http://www.bipro.net/namespace/transfer" 
xmlns:ns44="http://www.bipro.net/namespace/transfer/abrechnung" 
xmlns:ns45="http://www.bipro.net/namespace/transfer/gevo" 
xmlns:ns46="http://www.bipro.net/namespace/transfer/inkassostoerfall" 
xmlns:ns47="http://www.bipro.net/namespace/transfer/schaden-leistung" 
xmlns:ns48="http://www.bipro.net/namespace/transfer/schadenrueckfrage" 
xmlns:ns49="http://www.bipro.net/namespace/transfer/sepa" 
xmlns:ns50="http://www.bipro.net/namespace/transfer/vertrag" 
xmlns:ns51="http://www.bipro.net/namespace/kontext/beruf" 
xmlns:ns52="http://www.bipro.net/namespace/kontext/betriebsart" 
xmlns:ns53="http://www.bipro.net/namespace/kontext/fahrzeug" 
xmlns:ns54="http://www.bipro.net/namespace/kontext/partner" 
xmlns:ns55="http://www.bipro.net/namespace/kontext/schaden" 
xmlns:ns56="http://www.bipro.net/namespace/kontext/unternehmen" 
xmlns:ns57="http://www.bipro.net/namespace/kontext/vertrag" 
xmlns:xmime="http://www.w3.org/2005/05/xmlmime">             <ns43:Response>
            <ns2:BiPROVersion>2.6.1.0.0</ns2:BiPROVersion>
            <ns2:Status>
                <ns2:ProzessID>1530635989611</ns2:ProzessID>
                <ns2:Zeitstempel>2018-07-03T18:41:12</ns2:Zeitstempel>
                <ns2:StatusID>OK</ns2:StatusID>
                <ns2:Schwebe>false</ns2:Schwebe>
                <ns2:Meldung>
                    <ns2:ArtID>Hinweis</ns2:ArtID>
                    <ns2:MeldungID>04000</ns2:MeldungID>
                </ns2:Meldung>
            </ns2:Status>
            <ns43:Lieferung>
                <ns43:ID>1530636072667</ns43:ID>
                <ns43:Einstellzeitpunkt>2016-12-05T00:00:00</ns43:Einstellzeitpunkt>
                <ns43:Kategorie>120000000</ns43:Kategorie>
                <ns43:VerfuegbarBis>2019-12-05</ns43:VerfuegbarBis>
                <ns43:Transfer xsi:type="ns45:CT_GeVoTransfer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

有没有人有想法并能指出正确的方向?

Lexicore 要求 2 件事。 1. 完整的 XSD,您可以从我位于 https://github.com/JoBieker/soap-bipro/tree/master/securess-bipro/src/main/resources/xsd 的公开 github 存储库中获取。 2. 完整的 xml,我没有,因为我想创建它。但如果我能成功的话,像这样的东西应该会出来。这是另一个gevo-transfer case,但结构应该是一样的。您可以在这里下载:https://github.com/JoBieker/soap-bipro/blob/master/securess-bipro/src/main/resources/target-xml.xml

最后 lexicores 问题告诉我我完全忘记了我想编组 xml。所以在这里,我的 public github 存储库中有代码:https://github.com/JoBieker/soap-bipro 这是控制台提供的完整异常:

2018-07-04 22:19:46.407 ERROR 12986 --- [ main] o.s.boot.SpringApplication
: Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securessBiproApplication': Unsatisfied dependency expressed through field 'marshaller'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createJaxb2Marshaller' defined in class path resource [de/securess/bipro/config/Jaxb2Config.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'context.path' in value "${context.path}" at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1350) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:580) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE] at de.securess.bipro.SecuressBiproApplication.main(SecuressBiproApplication.java:43) [classes/:na] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'createJaxb2Marshaller' defined in class path resource [de/securess/bipro/config/Jaxb2Config.class]: Unexpected exception during bean creation; nested exception is java.lang.IllegalArgumentException: Could not resolve placeholder 'context.path' in value "${context.path}" at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=12=](AbstractBeanFactory.java:317) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ... 18 common frames omitted Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'context.path' in value "${context.path}" at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:172) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:237) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:211) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.lambda$processProperties[=12=](PropertySourcesPlaceholderConfigurer.java:175) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.resolveEmbeddedValue(AbstractBeanFactory.java:839) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1086) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:474) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1256) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1105) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:503) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE] ... 26 common frames omitted

此致,jcb

我想通了。

问题不在编组中,而是在验证中。

您已将 JAXB 配置为根据指定的模式验证编组 XML:

    marshaller.setSchemas(
            new ClassPathResource("/xsd/bipro-nachrichten-2.6.0.xsd"),
            new ClassPathResource("/xsd/bipro-transfer-2.6.0.xsd"),
            new ClassPathResource("/xsd/bipro-transfer-gevo-2.6.0.xsd"),
            new ClassPathResource("/xsd/bipro-gevo-2.6.0.xsd"),
            new ClassPathResource("/xsd/bipro-prozesse-vertrag-2.6.0.xsd"),
            new ClassPathResource("/xsd/bipro-basis-2.6.0.xsd")
            );

问题出现在 CT_Geschaeftsvorgang 类型的 ArtID 元素中。这就是您在 Java 代码中设置此元素的方式:

    JAXBElement<String> value = new JAXBElement<String>(
            new QName("http://wwww.bipro.net/namespace/transfer/gevo","ArtID"), String.class, "value"
            );
    value.setValue("120000000");
    CTGeschaeftsvorgang ctVertragsauskunft = new CTVertragsauskunft();
    ctVertragsauskunft.setArtID(value);

注意命名空间 URI:http://wwww.bipro.net/namespace/transfer/gevo,在 gevo.

之前有四个 wtransfer

现在,如果您仔细检查您的模式 bipro-gevo-2.6.0.xsd,您会发现它有一个不同的命名空间:

正确的命名空间是 http://www.bipro.net/namespace/gevo.

您的 Java 代码中的

Changing http://wwww.bipro.net/namespace/transfer/gevohttp://www.bipro.net/namespace/gevo 解决了问题。