Spring boot getting started hello world example

Lets create simple hello world rest example using spring boot.

Step 1 – Spring boot @EnableAutoConfiguration

This annotation tells Spring Boot to “guess” how you will want to configure Spring, based on the jar dependencies that you have added. Since spring-boot-starter-web added Tomcat and Spring MVC, the auto-configuration will assume that you are developing a web application and setup Spring accordingly.

package com.candidjava.spring.boot.helloworld;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

public class Example {

    String home() {
        return "Hello";

    public static void main(String[] args) throws Exception {
        SpringApplication.run(Example.class, args);



Step 2 – Spring boot starter parent and Spring boot starter web

Add spring boot parent and starter web dependency in maven pom.xml

To know more refer spring boot starter

<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">





Running this example

Use maven goal as

mvn spring-boot:run


Spring boot will deploy your code in tomcat with default 8080 port, now open your browser and type localhost:8080




Download :  spring boot helloworld maven


Leave a Reply

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