Eclipse Java Jaxb2插件生成WSDL时CreateRequest方法缺失求助
CreateRequest Method Isn't Appearing in the Generated WSDL Let’s break down the root cause and fix this issue step by step:
The core problem here is that your XSD only defines XML data structures (types and root elements for requests/responses), but a complete WSDL requires a service contract that maps those data structures to SOAP operations, messages, and ports.
The Maven JAXB2 plugin only handles converting XSD schemas to Java data classes—it doesn’t define the actual SOAP service interface that tells your framework which operations to expose. Without that service interface, your SOAP configuration has no way to generate the xs:message, portType, and binding sections needed for SoapUI to send valid requests.
Step-by-Step Solution
1. Create a JAX-WS Service Interface
You need to define a service interface with JAX-WS annotations to link your JAXB-generated Java objects to a SOAP operation. Here’s an example tailored to your XSD:
import javax.jws.WebMethod; import javax.jws.WebParam; import javax.jws.WebResult; import javax.jws.WebService; import com.your.package.CreateRequestInput; import com.your.package.CreateRequestOutput; @WebService(targetNamespace = "http://www.ima.eu/xml/cattolica") public interface RequestService { @WebMethod(operationName = "CreateRequest") @WebResult(name = "CreateRequestOutput", targetNamespace = "http://www.ima.eu/xml/cattolica") CreateRequestOutput createRequest( @WebParam(name = "CreateRequestInput", targetNamespace = "http://www.ima.eu/xml/cattolica") CreateRequestInput input ); }
@WebServiceties the interface to your XSD’s target namespace.@WebMethodmarks the method as a SOAP operation namedCreateRequest.@WebParamand@WebResultmap method parameters/return values directly to your XSD’s root elements.
2. Implement the Service Interface
Write a concrete implementation with your business logic:
public class RequestServiceImpl implements RequestService { @Override public CreateRequestOutput createRequest(CreateRequestInput input) { // Add your business logic here to process the input CreateRequestOutput output = new CreateRequestOutput(); CreateRequest response = new CreateRequest(); response.setIdCRM("GENERATED-CRM-ID"); response.setStatus("SUCCESS"); output.setCreateRequest(response); return output; } }
3. Update Your SOAP Configuration
Depending on your framework, configure the service to be exposed:
For Plain JAX-WS (No Spring)
Publish the service directly on startup:
import javax.xml.ws.Endpoint; public class ServicePublisher { public static void main(String[] args) { Endpoint.publish("http://localhost:8080/requestService", new RequestServiceImpl()); } }
For Spring (Traditional or Boot)
Use Spring’s JAX-WS support to expose the service:
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter; @Configuration public class SoapConfig { @Bean public SimpleJaxWsServiceExporter jaxWsServiceExporter() { SimpleJaxWsServiceExporter exporter = new SimpleJaxWsServiceExporter(); exporter.setBaseAddress("http://localhost:8080/"); return exporter; } @Bean public RequestService requestService() { return new RequestServiceImpl(); } }
4. Verify the WSDL
Start your application and visit the WSDL URL (e.g., http://localhost:8080/requestService?wsdl). You’ll now see:
- The existing
xs:typessection (from your XSD) xs:messagedefinitions for theCreateRequestrequest and response- A
portTypewith theCreateRequestoperation - SOAP
bindingandportelements
This will allow SoapUI to parse the WSDL and generate valid request/response messages.
内容的提问来源于stack exchange,提问作者Marco Bozzola

