CXF REST Without Spring

CXF REST Without Spring explains step by step details of Creating / Developing CXF JAX-RS (Restful) services without any spring dependencies

JAX-RS is Java API for RESTful Webservices which is very rely upon Representational State Transfer model, you can view JAX-RS specification. JAX-RS uses annotations for simplifying the development efforts.

Most of the tutorial related to Apache CXF is developed using spring framework, this is because of easy integration with spring. But it is not a necessity.

You can see the below example, which is demonstrating How to create a Restful service using CXF without any spring dependencies

Required Libraries

You need to download

  1. JDK 7
  2. Eclipse 4.2
  3. CXF-2.7.3
  4. Tomcat 7

Following jar must be in classpath

  1. cxf-2.7.3.jar
  2. httpasyncclient-4.0-beta3.jar
  3. httpclient-4.2.1.jar
  4. httpcore-4.2.2.jar
  5. httpcore-nio-4.2.2.jar
  6. neethi-3.0.2.jar
  8. xmlschema-core-2.0.3.jar
  9. jettison-1.3.3.jar (JSON library)

CXF REST Without Spring

I am creating a sample restful service project that pass Student object and return with some changes on that object. The service is using simple POJO (Plain Old Java Object) bean.

Firstly create a Dynamic Web Project (File->New->Dynamic Web Project) named "CXFRestfulTutorial" according to following screenshot

CXF REST Without Spring CXF REST Without Spring

Create a Student Object

package com.student;

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "Student")
public class Student {
private String name;

public String getName() {
return name;

public void setName(String name) { = name;

Here @XmlRootElement(name = "Student"), is a JAXB convention specifies that Student is XML document.

If you are specifies that @Produces("application/json") then Jettison library converts the JAXB to json text as response

1 2 3 Next

2 Responses to "CXF REST Without Spring"
  1. jan 2012-10-11 08:09:53.0
  1. Demerre 2016-07-27 08:10:38.0

Your email address will not be published. Required fields are marked *