Spring boot hello world example – Using Eclipse and Maven

Spring boot makes development process of application easier and less time consuming. It provides quick start to the application development with the help of starter dependencies which reduces time taken by the application developer for writing boiler plate codes.

In this post we will see how to create a simple spring boot application which prints “hello world”. In this post, we are using Maven build tool for developing our application along with Eclipse IDE.

Also we are using tomcat embed servlet container for running our application.

Following are the steps to create our first spring boot “hello world” application:

  • Create a maven project and modify the pom.xml content with following content.
  • Here, we are using spring-boot-starter-parent as parent project.
  • Adding spring-boot-starter-web dependency adds all required spring boot dependency jars into our application.


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <!-- Inherit defaults from Spring Boot -->
  <!-- Use java version 1.7 -->
    <!-- Add typical dependencies for a web application -->
  • create a java class named as Application.java under com.asb package and add the following content. This class is the entry point of our spring application. This class contains a main() method, which is executed while starting our spring boot application.
  • @SpringBootApplication : This annotation adds provides our application with basic required configurations. By using this annotation, following annotations are internally  added : @Configuration, @EnableAutoConfiguration and @ComponentScan.
  • @Configuration : Makes the current class as source of bean definitions.
  • @EnableAutoConfiguration : Makes all beans available for application, based on class path settings, other beans and other property settings.
  • @ComponentScan : Spring application looks for classes, components, services, etc defined from this package level.
  • SpringApplication.run() will start our application once our application is run.

Application.java :

package com.asb;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
public class Application {
    public static void main(String[] args) throws Exception {
         SpringApplication.run(Application.class, args);
  • Create a controller class called MyController.java under package com.asb.controller as shown below.
  • @Controller : Makes the class a spring controller.
  • @RequestMapping : Used to map the requests into the defined request handler method. In this example, all the requests are handled by the method getMessage()
  • upon hitting the application(http://localhost:8080/), browser will display “hello world” string message on browser.

MyController.java :

package com.asb.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

public class MyController {
    public String getMessage(){
        return "hello world";
  • finally run the application by Right click on Application.java class > Run as > Java application.


  • This will run our spring application. and console will display that application is up and running on port 8080 as shown below.

spring start

  • Following is the out put of our application displaying “hello world” upon hitting the application URL on browser(http://localhost:8080/).

spring-boot-hello-world example

Version Details:

  • Spring Boot 1.4.2.RELEASE
  • Eclipse Neon.2 Release (4.6.2)

Also read: