CXF REST Exception Handling

Note; On the above ChangeStudentDetailsImpl class, implementing an interface is not necessity, you can create restful services without implementing an interface.

@Consumes annotation specifies, the request is coming from the client

you can specify the Mime type as @Consumes("application/xml"), if the request is in xml format

@Produces annotation specifies, the response is going to the client

you can specify the Mime type as @Produces ("application/xml"), if the response need to be in xml format


CXF is using Spring internally, Finding classes by spring we need to add service implementation beans are added on "jaxrs:serviceBeans".

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <jaxrs:server id="base" address="/rest">
            <ref bean="StudentService" />
    <bean id="StudentService" class="com.student.ChangeStudentDetailsImpl" />


Change the web.xml file to find CXF servlet and cxf.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns=""

Publishing CXF Restful Service

CXF REST Exception Handling


You can Find all the deployed JAX-WS/JAX-RS services you need to append 'services' at the end of the URL so URL will become following


Previous 1 2 3 4 Next

3 Responses to "CXF REST Exception Handling"
  1. harry 2012-11-17 09:30:35.0
  1. admin 2012-11-18 09:30:35.0
  1. Joe 2012-11-19 09:30:35.0

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