Square CSS

Showing posts with label Spring Boot. Show all posts
Showing posts with label Spring Boot. Show all posts

Thursday, October 18, 2018

Spring Boot : Hello World Example

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.

Refer the video tutorial :




Spring Boot Starter

In big projects, it becomes difficult to handle dependencies. Spring boot provides a set of dependencies which can be easily implemented.

For providing dependency a developer can provide the artifactId as spring-boot-starter-*  where "*" is the application type in lowercase.

For example, if JPA application needs to be developed just provide spring-boot-starter-jpa in the artifactId.


Let's have a look over some examples :


Security implementation using Spring Boot Starters -

  
   <dependency>
       <gropuId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-security</artifactId>    
   </dependency>


Thymleaf implementation using Spring Boot Starters -

  
   <dependency>
       <gropuId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-thymleaf</artifactId>    
   </dependency>


  Next >> SpringApplication
                      SpringApplication is a class which has a static parametrized method ...


Spring Boot : Introduction

Spring Boot provides the Java developers to create a stand-alone application with an ease which the developer can just run in no time. With the minimal configuration requirement, Spring Boot is becoming popular day by day.




Benefits of using Spring Boot :

  • Easy to use.
  • Reduction in the time of production.
  • Easy to work with data layers using annotation based configurations.
  • Increase in productivity.
  • Reduction in complexity.

      Next >> Spring Boot Starters
                         In big projects, it becomes difficult to handle dependencies. Spring boot ... 


    Some Algorithms

    Algorithm: Tower of Hanoi

    Tower of Hanoi consists of three towers called as pegs with n number of rings. Rings are of different size.  Conditions to be fulfill...

    Popular Posts