4. Implementing Spring Web Services for SOAP - Maven Archetype
Using a Spring Web Services Archetype
In this section, you will create a boilerplate Spring Web Services project in Eclipse using the Spring Web Services Maven Archetype.
Steps:
- Project Setup
- Step 1: Open Eclipse
- Launch Eclipse IDE on your computer.
- Step 2: Create a New Maven Project
- Go to
File > New > Project. - Select
Maven Projectfrom the list and clickNext.
- Go to
- Step 3: Select Project Location
- Choose the workspace location for your project or accept the default location and click
Next.
- Choose the workspace location for your project or accept the default location and click
- Step 4: Select an Archetype
- In the Archetype selection window, click
Add Archetype. - Enter the following details:
- Group Id:
org.springframework.ws - Artifact Id:
spring-ws-archetype - Version:
2.4.0(or the latest version available)
- Group Id:
- Click
OK, then select the added archetype and clickNext.
- In the Archetype selection window, click
- Step 5: Define Project Coordinates
- Enter the following details:
- Group Id:
com.nicordesigns - Artifact Id:
spring-ws-charityregistration - Version:
1.0-SNAPSHOT
- Group Id:
- Click
Finish.
- Enter the following details:
- Step 1: Open Eclipse
- Configuration
- Step 1: Open Spring Configuration File
- Navigate to
src/main/resourcesand open the Spring configuration file (applicationContext.xmlor in our caseweb.xmlandspring-ws-servlet.xml).
- Navigate to
- Step 2: Enable WSDL Generation
- Add the necessary configurations to generate the SOAP WSDL file automatically. This typically involves defining beans for
DefaultWsdl11DefinitionandXsdSchema.
- Add the necessary configurations to generate the SOAP WSDL file automatically. This typically involves defining beans for
- Step 1: Open Spring Configuration File
- Service Layer Development
- Step 1: Create Service Interface
- In the
src/main/javadirectory, create a new package and a Java Interface for your service. Interface name to align with generated WSDL wsdl:portType
- In the
- Step 2: Implement Service Interface
- Create an implementation class for the service interface.
- Step 1: Create Service Interface
- SOAP Endpoint Implementation
- Step 1: Define Endpoint Class
- Create a new class for your SOAP endpoint and annotate it with
@Endpoint.
- Create a new class for your SOAP endpoint and annotate it with
- Step 2: Map Requests to Methods
- Use
@PayloadRoot,@RequestPayload, and@ResponsePayloadannotations to map incoming SOAP requests to appropriate methods.
- Use
- Step 1: Define Endpoint Class