Create a Spring Boot application to print "Hello World".
Prerequisites for Creation of Spring Boot :
- Java with version 1.6 or above. Better to use the latest version.
- If using Maven then 3.2 or above.
- If using Gradle then 2.9 or above.
- Plugin of Spring Tool Suit enabled in IDE like eclipse.
- Basic knowledge of Spring Framework.
Versions Used :
- Java 1.8
- Spring Boot 1.5.9
- Eclipse 4.6.9 Neon
Create a Maven project and provide the dependency :
- Go to File >> New >> Maven Project.
- Provide Artifact Id as your project name. In this case, it is SpringBootTutorial.
- Provide the following dependencies in the pom.xml file.
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.9.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> </dependencies> |
- Provide the mapping for the method to return "Hello World".
@Controller @EnableAutoConfiguration public class SpringBootTutorial{ @RequestMapping("/") @ResponseBody String Home() { return "Hello World"; } public static void main(String[] args) { SpringApplication.run(SpringBootTutorial.class, args); } } |
- Run as Spring Boot App.
- Go to the browser and provide the URL localhost:[portNumber]/pathForMethod.
No comments:
Post a Comment