Spring Boot Hello World Example is demonstrated here with Eclipse IDE.
Spring Boot Setup
To start with Spring Boot Hello World Example first install STS (Spring Tool Suite) 4 Plugin from Eclipse Marketplace.
After Installing STS 4 plugin, In Eclipse go to File -> New -> Other -> Spring Boot -> Spring Starter Project
Now with default settings click next.
After clicking Finish, it may take few seconds to import the project.
package com.digitizedpost.springboot.maven.helloworld;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootHelloWorldExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootHelloWorldExampleApplication.class, args);
}
}
Run the above program as Spring Boot App. If you see 'Started AngularSpringBootIntegrationApplication in some seconds' message in the eclipse console, your spring boot project is up and running.
Spring Boot Web Starter Hello World
Now we have done the setup. Next we can see the Hello World Example by adding Web Starter to the project.
Add a new Spring Boot Starter dependency to the existing project
You can add a new Spring Boot Starter dependency using the Spring Initializr web application or by using the Eclipse STS plugin or by Spring Tool Suite IDE. Here we are going to add a new Web Starter dependency using the STS plugin.
Right click on the project -> Spring -> Edit Starters -> Spring Web
Add the below REST API program with a single method and return the Hello World string.
package com.digitizedpost.springboot.maven.helloworld;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringBootRestController {
@RequestMapping("/")
public String hello() {
return "Hello World from Spring Boot App!";
}
}
Clean the Project and go to the SpringBootApplication main class and Run the Project as Java Application or Spring Boot App.
By default the Spring Boot Application will run with Embedded Tomcat Server in 8080 port.
Open the browser with 8080 default port or if the port is not available, change it to 8081 port or any other available port. Now will see the Hello World message in the browser.