Java 创建DefaultWsdl11Definition bean时XsdSchema和XsdSchemaCollection之间的JAXB差异

Java 创建DefaultWsdl11Definition bean时XsdSchema和XsdSchemaCollection之间的JAXB差异,java,spring,spring-boot,jaxb,maven-jaxb2-plugin,Java,Spring,Spring Boot,Jaxb,Maven Jaxb2 Plugin,我研究了JAXB和JAXB2 Maven插件。我对bean实例化感到困惑 我在src/main/resources中有两个模式,它们具有相同的名称空间www.mycompany.comschemaA.xsd和schemaB.xsd具有相同的标题: <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.mycompany.com" targetNamespace="http:/

我研究了JAXB和JAXB2 Maven插件。我对bean实例化感到困惑

我在
src/main/resources
中有两个模式,它们具有相同的名称空间
www.mycompany.com
schemaA.xsdschemaB.xsd具有相同的标题:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:tns="http://www.mycompany.com"
    targetNamespace="http://www.mycompany.com"
    elementFormDefault="qualified">
和WSDL bean:

@Bean(name = "soapWsdl")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema, XsdSchemaCollection schemaCollection) {
    DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    wsdl11Definition.setPortTypeName("SoapPort");
    wsdl11Definition.setLocationUri("/service/soap");
    wsdl11Definition.setTargetNamespace("https://www.mycompany.com");

    // At this point I use just one of the folliwing
    wsdl11Definition.setSchema(schema);
    wsdl11Definition.setSchemaCollection(schemaCollection);

    return wsdl11Definition;
}
在上面的bean中使用其中一个:

  • wsdl11Definition.setSchema(模式)

    如果我只使用
    XsdSchema
    定义一个模式(不管是schemaA还是schemaB),那么一切都可以工作,soapweb服务正在运行,WSDL也会生成

  • wsdl11Definition.setSchemaCollection(schemaCollection)

    现在,虽然将一个模式设置为具有一个模式的集合,但仍会抛出NPE。引发的错误是:

    2018-10-05 21:29:28.636警告164968---[main]ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.BeanCreationException:创建在类路径资源中定义了名称为“soapWsdl”的bean时出错[cz/vse/soap/WebServiceConfig.class]:通过工厂方法实例化Bean失败;嵌套异常为org.springframework.beans.beanInstationException:实例化[org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition]失败:工厂方法“defaultWsdl11Definition”引发异常;嵌套异常为java.lang.NullPointerException

  • 下面是一点:

    原因:java.lang.NullPointerException:null 在org.springframework.xml.xsd.simplexsdsdsdschema.getTargetNamespace(SimpleXsdSchema.java:94)~[spring-xml-3.0.3.RELEASE.jar!/:na] 在com.mycompany.WebServiceConfig.defaultWsdl11Definition(WebServiceConfig.java:66)~[classes!/:0.0.1]


我通过调用
simplexsdsdschema::afterPropertiesSet
来实现这一点,但bean实例化并未以某种方式调用它。很难说会发生什么。但是,编辑这样的方法会使模式协同工作:

@Override
public XsdSchema[] getXsdSchemas() {
    SimpleXsdSchema[] schemaArray = new SimpleXsdSchema[] {
            new SimpleXsdSchema(new ClassPathResource("xsd/schemaA.xsd")),
            new SimpleXsdSchema(new ClassPathResource("xsd/schemaB.xsd"))
    };

    for (SimpleXsdSchema schema : schemaArray) {
        try {
            schema.afterPropertiesSet();
        } catch (ParserConfigurationException | IOException | SAXException e) { /* ...*/}
    }       
    return schemaArray;
}
有人知道会发生什么吗?为什么传递
XsdSchema
XsdSchemaCollection
的行为不一样,即使它们应该根据

@Override
public XsdSchema[] getXsdSchemas() {
    SimpleXsdSchema[] schemaArray = new SimpleXsdSchema[] {
            new SimpleXsdSchema(new ClassPathResource("xsd/schemaA.xsd")),
            new SimpleXsdSchema(new ClassPathResource("xsd/schemaB.xsd"))
    };

    for (SimpleXsdSchema schema : schemaArray) {
        try {
            schema.afterPropertiesSet();
        } catch (ParserConfigurationException | IOException | SAXException e) { /* ...*/}
    }       
    return schemaArray;
}