# 'Hello World' Application

In 
Published 2022-12-03

This tutorial shows you how to create a simple 'Hello World' Spring Boot application.

Spring Boot is designed to speed up the development of Spring applications by writing less boilerplate code. Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". Most Spring Boot applications need very little Spring configuration. Before learning Spring Boot, you must have the basic knowledge of Spring Framework.

What you need is to:

  • create a simple Spring Application configured with Maven
  • configure spring-boot-starter-parent in your pom.xml file
  • in the same file you need to configure also the required starter projects and spring-boot-maven-plugin

Here you can see a simple pom.xml file configuration for a simple "Hello World" Spring Boot Application:

Note that:

  1. spring-boot-starter-parent inherits from spring-boot-dependencies which is defined at the top of the POM.

  2. spring-boot-starter-parent dependency contains the default version of Java to use, the default versions of dependencies Spring Boot uses and the default configuration of Maven plugins.

  3. starter projects are dependencies grouped for different purpose. If you include the spring-boot-starter-web as starter project in your Spring Boot Application, the following dependencies will be loaded automatically by Maven: spring-boot-starter, spring-boot-starter-tomcat, hibernate-validator, spring-web, jackson-databind, spring-webmvc.

  4. spring-boot-maven-plugin provides several goals for Maven Spring Boot Application : you can run the Spring Boot Application without creating the JAR or WAR file or you can create the JAR/WAR files for later deployments.

When all of these are done, the following step is to create the Spring Boot launch class. Here is my example for my Hello World Spring Boot Application :

package com.example.main;
 
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringHelloWorldApplication {
 
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(SpringHelloWorldApplication.class, args);
         
        System.out.println("Application is running ...");
         
        System.out.println("Hello World !");
    }
}

NOTES:

  1. @SpringBootApplication annotation is a shortcut for the following annotation: @Configuration, @EnableAutoConfiguration, @ComponentScan

  2. the scanning for Beans in done only in the current package and all its subpackages.

  3. Spring Boot Autoconfiguration creates and configure Context Beans automatically based on the dependencies we have chosen.

When we run the Hello World Spring Boot Application we receive the following output: