Hello World in Spring Boot
Hey folks! All we know that what is hello world program. It’s a very simple example to go ahead in any language, so we are here to express interest in this course so that you will be in touch from base to expertise level in development with spring boot microservices.
Download Example Hello World
You can download the application here, in this download folder you will see some of the images that will help you to understand the project.
Now, we are going to see the hello world example in spring boot……
Lets follow the simple steps to create spring boot application in java……
STEP 1. Go to theLink
STEP 2.Fill the group and artifect id and add the dependencies.
STEP 3.Download the zip.
STEP 4.Unzip in the eclipse workspace and open it while you are using internet, so that maven can download the jar from maven repository..
STEP 5.After downloading all the jar your project will look like as below:-
Now use the following steps to run this project.
Now, follow the steps and see the output
There is no any error, it looks like this is error, but this is default error page from spring boot that handles the exception.
To complete the example of hello world we need a controller to display the hello world.
package com.techieuncle.restwebservice.restwebservice.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class MainController {
@GetMapping("/greetings")
public String GreetingMethod() {
return "Hello World";
}
}
Now the output will be as below:
What is POM.XML?
After downloading the spring-boot template project and you will see many files including pom.xml since this is maven project. You have to understand one thing that what are inside in pom.xml
You can see in this pom.xml file there is project tag and it have parent tag with three sub-attribute like groupId and that have
org.springframework.boot as value and artifactId tag have value spring-boot-starter-parent and version tag will have similar to 2.3.3.RELEASE
Parent section in this pom.xml says that this project is a child of spring boot. This child and parent concept is happening due to maven. since maven idea have parent and child concept in which child can inherits parent.
Here, parent spring boot project is spring-boot-starter-parent.
Other than these tag, we have dependency tag, it means spring boot says if you want to inherits our parent project, you need some metadata to run this project
you can see here.
So, after the 1st step, you have to download all these dependencies from maven central. like spring-boot-starter-web artifactId in dependency tag
This is a parent metadata(or mini spring booot project) that have all the spring module related to web.
Thanks Reader...