Publishing Static WSDL and related XSD schemas using Spring WS
Spring web service has a way to do it elegantly actually.
All you need to do is to define a SimpleXsdSchema
bean with the right id (which will be used as the xsd name without .xsd) in the bean definition xml file, something like below
<bean id="my"
class="org.springframework.xml.xsd.SimpleXsdSchema">
<property
name="xsd"
value="/mypackage/my.xsd">
</property>
</bean>
More information (including an example) can be found at the following link: Static WSDL with imported XML Schema in Spring Web Service
Below is the Java config for exposing the schema. This worked for me. Please note that the schema name should match the Bean name and method name. This is very key for this to work. So I kept the XSD name and Bean name as "CustomerDetailsSchema" and make sure the constructor for getCustomerDetails also matches the name.
@Bean(name = "customerDetails")
public DefaultWsdl11Definition getCustomerDetails(XsdSchema CustomerDetailsSchema) {
DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
wsdl11Definition.setPortTypeName("...");
wsdl11Definition.setServiceName("...");
wsdl11Definition.setLocationUri("/webservice");
wsdl11Definition.setTargetNamespace("...");
wsdl11Definition.setSchema(CustomerDetailsSchema);
return wsdl11Definition;
}
@Bean(name = "CustomerDetailsSchema")
public XsdSchema CustomerDetailsSchema() {
return new SimpleXsdSchema(new ClassPathResource("schemas/CustomerDetailsSchema.xsd"));
}