Spring Boot Hello World example – JavaDream

Spring Boot Hello World example – JavaDream

We know that spring boot framework is an advance framework developed by the pivotal. Using Spring boot we can setup the spring boot hello world example application within 5 minutes.

If we talk about spring framework than this framework will take a very long time to setup the project. We have to define many xml for a tiny task. Using Spring boot we get rid of this and create our project within minutes.

So here we go now it’s time to create the spring boot hello world example. In this Project we just print the Hello Word on our Google Chrome web browser.

To create Spring Boot Hello World project we have to follow the below steps:

  1. First go to the Spring initializr website https://start.spring.io/
  2. Configure Project Metadata configuration
  3. Choose Spring Web dependency from Add Dependency tab.
  4. Click on GENERATE button now you will get a .zip file.
  5. Open your eclipse or any other editor and import this project.
  6. Now make a simple controller class using some spring boot annotation that return simple hello word while calling your end point.

Now follow above steps one by one

1- First we have to go to the spring initializer and here we select Project as Maven Project and Language as Java. Now choose Spring boot version currently we are using 2.3.3.

Now configure the Project Metadata details here you see many options and they are:

Group – It is your package name define so define accordingly here i am define com.vasu

Artifact and Name – Both are same after defining this you will get your complete pacakge like i am defining here myfirstproject. So my package name now become com.vasu.myfirstproject.

Description – Give description about your project.

Package name – It is the combination of Group and Artifact. It will autofill automatically.

Now define your Packaging type here we choose Jar.

Now choose your Java version minimum version is Java 8 for using Spring Boot.

spring boot hello world example
spring boot hello world example
spring boot hello world example

After clicking on GENERATE button you will get your project in .zip format. Now extract this project and open in your eclipse or any other editor.

Now In Your Eclipse Project Structure is like :

spring boot hello world example

your MyfirstprojectApplication.java class is using the annotaion @SpringBootApplication that defines it is you main class you have to run this class to start your project.

Now it’s time to return Hello Word from our application to Chrome Console. So for that create a controller class. We are creating with name MyFirstController.java class.

Here In this class we define two annotaions

  1. @RestController
  2. @GetMapping

@RestController annotation is used to define that our class return object as output we can return any object in this case we simply return the String Object.

@GetMapping annotaion is used to define end point here we define (“/) means if we hit http://localhost:8080 on our browser than we will get the output:

package com.vasu.myfirstproject.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

public class MyFirstController {

	public String test() {
		return "Hello Word";

Application Run Steps:

Right click on MyfirstprojectApplication.java class. Click on Run As now click on Java Application. congrats your application is start now.

Now run your application and hit http://localhost:8080 URL you will get “Hello Word” as output.

spring boot hello world example

Complete code on Github- Spring Boot Hello Word GitHub URL

You may also like:

Create WAR of Spring Boot Project

How to use H2 database in spring boot application

Help Others, Please Share

Leave a Reply

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