Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

A simple RESTful Web Service based on Spring Web MVC

A simple application just contains a controller which provides three methods:

  • textMessage() - returns a simple text message getted from a service-class.
  • jsonMessage() - returns a JSON message that is the result of simple POJO's content conversion.
  • xmlMessage() - returns an XML message that is the result of simple POJO's content conversion. Using JAXB annotations with Jackson is shown.

The methods are mapped on a common path: /api/message. The Accept HTTP header is important for method dispatch.

How to build

Please, use Apache Maven to build the project.

$ git clone
$ cd spring-4x-demos/rest-web-service
$ mvn clean package

How to run

The project uses Liberty Maven Plug-in to automatically download and install WebSphere Liberty profile runtime from the Liberty repository. Liberty Maven Plug-in is also used to create, configure, and run the application on the Liberty server.

Use the following simple three steps to run the application with Maven:

  1. Execute the Liberty Maven Plug-in to download, install and create Liberty profile server.

    $ mvn liberty:create-server

    The Liberty profile kernel archive contains about 11 MB, i.e. Apache Tomcat 8.0.30 is just only about 2 MB less.

  2. Install the servlet-3.1 feature into the created server.

    $ mvn liberty:install-feature
  3. To run the server with the example execute:

    $ mvn liberty:run-server

Once the server is running, the application will be available under http://localhost:9082/rest-web-service/api/message.

How to get a result

You can call the controller just using the following code snippet:


public class SimpleInvokator {

    public static void main(String[] args) {
        WebTarget target = ClientBuilder.newClient().target(

        String restext = target

        String resjson = target

        String resxml = target

Jersey 2 should be downloaded for the invokator.

A result looks like the following:

{"orderName":"IBM zShop","orderCount":441}
<zshop orderName="IBM zShop" orderCount="648" xmlns=""></zshop>