gpt4 book ai didi

java - Spring 4、SOAP WS、XSD...产生两种不同的 WSDL

转载 作者:行者123 更新时间:2023-11-30 10:43:14 28 4
gpt4 key购买 nike

第二次我试图在没有任何答案的情况下提出这个问题,尽管我认为这对于一个优秀的 Spring 开发人员来说不应该是一个难题..

我想创建一个简单的 Spring 4(注释驱动)应用程序,这将使用 maven-jaxb-plugin 生成每个请求响应对象工厂和对象映射类...

我希望此应用程序生成 2 个 WSDL,因此根据我的假设,我从两个不同的 XSD 开始,并使用两个不同的 SPRING WsConfigurerAdapter 类来配置 WSDL,显然还有两个不同的类来管理端点..

一切正常...但我的问题是:

I ve a bean shared between the two WSDL, and consequently between the two XSD, how to accomplish this? XSD and Maven Plugin side, everything keep working as well if i declare a complex type inside an XSD and than import or include it into the second one, but SPRING 4 side, when i just add the import and the bean, the WSDL with the import has not been resolved, something like unexpected end of file, it's obvious that i'm missing or making something wrong... but what?

声明共享实体的第一个 XSD..

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:usr="http://concretepage.com/soap/userManagement" targetNamespace="http://concretepage.com/soap/userManagement">

<xs:element name="getUserRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="userId" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getUserResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="user" type="usr:user" />
</xs:sequence>
</xs:complexType>
</xs:element>

<!-- share bean -->
<xs:complexType name="user">
<xs:sequence>
<xs:element name="userId" type="xs:int" />
<xs:element name="userName" type="xs:string" />
<xs:element name="age" type="xs:int" />
<xs:element name="password" type="xs:string" />
<xs:element name="passwordffd" type="xs:string" />
</xs:sequence>
</xs:complexType>

</xs:schema>

第二个 XSD,现在对导入进行了注释并且一切都像这样工作,但是没有将元素 User 注入(inject)到作业中,如果我通过导入启用它,则 jobManagement WSDL SOAP-UI 加载失败:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://concretepage.com/soap/jobManagement" targetNamespace="http://concretepage.com/soap/jobManagement"
xmlns:usr="http://concretepage.com/soap/userManagement">
<!-- import -->
<!-- xs:import schemaLocation="userManagement.xsd"
namespace="http://concretepage.com/soap/userManagement" / -->

<xs:element name="getJobRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="jobId" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="getJobResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="job" type="tns:job" />
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="job">
<xs:sequence>
<xs:element name="jobId" type="xs:int" />
<xs:element name="jobName" type="xs:string" />
<xs:element name="jobRole" type="xs:string" />
<xs:element name="salary" type="xs:int" />
**<!-- xs:element name="user" type="usr:user" /-->**
</xs:sequence>
</xs:complexType>
</xs:schema>

这是生成具有共享 bean 的 WSDL 的 Spring 类:

@Configuration
@EnableWs
@ComponentScan("com.concretepage")
public class JobConfig extends WsConfigurerAdapter {

@Bean(name = "jobManagement")
public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema jobSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("jobManagementPort");
wsdl11Definition.setLocationUri("/soapws/jobManagement/");
wsdl11Definition.setTargetNamespace("http://localhost:8080/spring4soap/");
wsdl11Definition.setSchema(jobSchema);

return wsdl11Definition;
}

@Bean
public XsdSchema jobSchema() {
return new SimpleXsdSchema(new ClassPathResource("jobManagement.xsd"));
}
}

最佳答案

好的,替换

wsdl11Definition.setSchema(jobSchema); 

通过

wsdl11Definition.setSchemaCollection(mySchemaCollection());

建立你的 Collection :

@Bean
public XsdSchemaCollection quotesSchemaCollection() {
return new XsdSchemaCollection() {

public XsdSchema[] getXsdSchemas() {
return new XsdSchema[]{new SimpleXsdSchema(new ClassPathResource("a.xsd")), new SimpleXsdSchema(new ClassPathResource("b.xsd"))};
}

public XmlValidator createValidator() {
throw new UnsupportedOperationException();
}
};
}

来源:Spring 文档 -> spring.io

关于java - Spring 4、SOAP WS、XSD...产生两种不同的 WSDL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37854490/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com