This sample explains how to create spring boot hello world application
Tools and technologies used for this application are-
Step 02 - Add dependencies to pom.xml file
Step 03 - Create Controller class(SpringBootController.java)
Step 04 - Create Main Class(MainApplication.java)
Step 05 - Run Application
Right click on MainApplication.java - > Run As -> Java Application
Step 06 - Get Output
Now, enter the http://localhost:8080 in browser's address bar and see the output
Tools and technologies used for this application are-
- Spring Boot 1.5.4.RELEASE
- JavaSE
- Maven
- Eclipse Neon
Here is project Structure
Step 01 - Create Maven project
File -> New -> Maven Project ->select Create a simple project ->Enter details and finish.
Step 02 - Add dependencies to pom.xml file
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boraji.tutorial.springboot</groupId>
<artifactId>spring-boot-hello-world-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>1.8</java.version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Step 03 - Create Controller class(SpringBootController.java)
package com.boraji.tutorial.springboot.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class SpringBootController{
@RequestMapping("/")
public String sayHello() {
return "Hello Spring Boot!!";
}
}
Step 04 - Create Main Class(MainApplication.java)
package com.boraji.tutorial.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class MainApplication{
public static void main(String[] args) {
SpringApplication.run(MainApplication.class, args);
}
}
Step 05 - Run Application
Right click on MainApplication.java - > Run As -> Java Application
Step 06 - Get Output
Now, enter the http://localhost:8080 in browser's address bar and see the output
This will help you to start spring boot world. Thank you!
ReplyDelete