Quick Guide
This page condenses the course into a checklist. Use it when you already understand the concepts and need the exact sequence for a new project.
1. Project setup
mvn archetype:generate -DgroupId=com.example \
-DartifactId=cxf-service -Dversion=1.0.0 \
-DarchetypeArtifactId=maven-archetype-quickstart \
-DinteractiveMode=false
<properties>
<maven.compiler.release>17</maven.compiler.release>
<cxf.version>4.0.5</cxf.version>
</properties>
Add cxf-rt-frontend-jaxws and cxf-rt-transports-http-jetty for SOAP, or cxf-rt-frontend-jaxrs for REST. Add cxf-rt-transports-jms and a broker client for JMS.
2. SOAP service
@WebService(targetNamespace = "http://ws.example.com/")
public interface Calculator {
int add(int a, int b);
}
@WebService(endpointInterface = "com.example.Calculator")
public class CalculatorImpl implements Calculator {
public int add(int a, int b) { return a + b; }
}
3. Publish
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceClass(Calculator.class);
factory.setServiceBean(new CalculatorImpl());
factory.setAddress("http://localhost:8080/calculator");
factory.create();
mvn -q compile exec:java -Dexec.mainClass=com.example.Server
curl "http://localhost:8080/calculator?wsdl"
4. Call
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(Calculator.class);
factory.setAddress("http://localhost:8080/calculator");
Calculator client = (Calculator) factory.create();
System.out.println(client.add(2, 3));
5. Contract-first variant
mvn generate-sources
# implement the generated SEI
# publish with setServiceClass(GeneratedSEI.class)
Add the cxf-codegen-plugin execution shown in the WSDL-first chapter and keep the WSDL in src/main/resources/wsdl.
6. REST resource
@Path("/employees")
@Produces(MediaType.APPLICATION_JSON)
public class EmployeeResource {
@GET
public List<Employee> list() { return repository.findAll(); }
}
JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean();
factory.setResourceClasses(EmployeeResource.class);
factory.setResourceProvider(EmployeeResource.class,
new SingletonResourceProvider(new EmployeeResource()));
factory.setProvider(new JacksonJsonProvider());
factory.setAddress("http://localhost:8080/api");
factory.create();
curl http://localhost:8080/api/employees
7. JMS variant
factory.setTransportId("http://cxf.apache.org/transports/jms");
factory.setAddress("jms:queue:order.queue");
factory.setProperties(Map.of(
"org.apache.cxf.transport.jms.brokerURL", "tcp://localhost:61616"));
Start a broker, publish the endpoint, and point the client at the same queue. Test redelivery and idempotency before trusting the queue in production.
8. Release checklist
- WSDL or OpenAPI published and reviewed.
- HTTPS and authentication enabled.
- Timeouts, retries, and idempotency documented.
- Integration tests run against a real endpoint.
- Logs include correlation IDs but no secrets.
- Broker queues and consumers monitored.
Back to course overview · Previous: Conclusion · Next: Useful Resources