Sunday, April 16, 2017
This section provides a quick introduction on how to develop a simple micro service which exposes a REST API using Spring Boot.

The intent is to do a simple “/sayhello” API which returns “Hello” as the output.

  • Open the Spring Tool Suite (STS) and click on Spring Starter Project.
Create a Spring Starter Project

  • Fill in the application details. For this example we would use Java 8 and Maven as the build system.
Spring Starter Project application details

  • Since we are exposing APIs from this application enable Web Services under Web. Refer the snapshot below.
Spring Starter Project Enable Web Services
  • Finish the application wizard and you would see the Spring project created and ready for use in Spring Tool Suite IDE. Under Maven dependencies all the dependent jars are already loaded. Also notice that pom.xml is created.
Spring Starter Project Application

  • Now let us understand the top level class.
package com.sourcetricks;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class MyFirstAppApplication {

   public static void main(String[] args) {, args);

@SpringBootApplication is a convenience annotation. The @SpringBootApplication annotation is equivalent to using @Configuration, @EnableAutoConfiguration and @ComponentScan with their default attributes if you are familiar with Spring annotations.

Otherwise we have one line of code in main program which launches the application.

  • Now let us introduce a new class HelloController which exposes the /sayhello API. This is achieved using @RestController and @RequestMapping annotations as shown below.

package com.sourcetricks;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class HelloController {

    public String hello() {
      return "Hello";

  • Now we can run the project as a Java application in the STS IDE and we should start to see the embedded tomcat coming up on port 8080.

2017-04-16 07:27:43.657  INFO 17584 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2017-04-16 07:27:43.790  INFO 17584 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2017-04-16 07:27:43.799  INFO 17584 --- [           main] com.sourcetricks.MyFirstAppApplication   : Started MyFirstAppApplication in 7.816 seconds (JVM running for 10.038)

  • Open a browser and invoke the /sayhello API we introduced.
Spring Boot Application - Launch Web Service
  • Next step is to package this application into a standalone application using Maven. If you notice the generated pom.xml file you will see the necessary build plugins already added since we selected Maven as the build system during project creation.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""


 <description>This is my first Spring Boot Web Service</description>

  <!-- lookup parent from repository -->





  • Go to the workspace folder where the application is stored in your workspace and run “mvn package” command. This builds and packages the application. You should see “MyFirstApp-0.0.1-SNAPSHOT.jar” bundled with all dependencies.
Maven standalone application package

  • You can test if the application starts up by running the command “java –jar MyFirstApp-0.0.1-SNAPSHOT.jar”. The same browser test can be done on the exposed API.

Now we are ready with a simple micro service based on Spring Boot. 


  1. Thank you for taking the time to provide us with your valuable information. We strive to provide our candidates with excellent care and we take your comments to heart.As always, we appreciate your confidence and trust in us
    Analytics Training In Chennai

  2. I want more and more articles and blogs please post soon such informative information.
    this guy makes good reviews

  3. Today’s GPS watches have all the sport-specific features to track every stride on the roads, but they’re also jammed with other sensors and technology—pairing with your smartphone—to keep you connected the rest of the day, too. Here are some of the top-of-the-line watches runners will want to check out Top GPS Watches

  4. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of the ideas can be nice content.The people to give them a good shake to get your point and across the command.

    AWS Training in HRBR Layout
    AWS Training in Kalyan Nagar
    Best AWS Training Institute in Kalyan Nagar Bangalore


Contact Form


Email *

Message *

Back to Top