Book Image

Building a RESTful Web Service with Spring

By : Ludovic Dewailly
Book Image

Building a RESTful Web Service with Spring

By: Ludovic Dewailly

Overview of this book

Table of Contents (17 chapters)
Building a RESTful Web Service with Spring
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Running the service


Building upon Chapter 2, Building RESTful Web Services with Maven and Gradle, we can quickly get our service up and running by using Spring Boot. For this purpose, we need to create a main class, as follows:

package com.packtpub.springrest.inventory;
// imports omitted
@SpringBootApplication
public class WebApplication {

  public static void main(String[] args) {
    SpringApplication.run(new Object[]{WebApplication.class, "inventory.xml"}, args);
    InventoryService inventoryService = context.getBean(InventoryService.class);
  }
}

Running this class in your favorite IDE will start an embedded Tomcat instance and expose your resources. The service will be accessible at http://localhost:8080. For example, accessing http://localhost:8080/rooms/1 will return the following:

{
  "id": 1,
  "name": "Room 1",
  "roomCategoryId": 1,
  "description": "Nice, spacious double bed room with usual amenities"
}

Note

We depart from Chapter 2, Building RESTful Web Services with Maven and...