Saturday, June 10, 2017

Spring Boot : Hands On Introduction


 Developing Web Application using SpringMVC and JPA (Non Spring Boot Way )
  1. Configure Maven Dependencies in pom.xml
  2. Configure Service/DAO layer beans using Java Config
    • Can configure DataSource, DataSourceInitializer, JPA Repo, Property Source etc
  3. Configure Spring MVC web layer beans
    •  Configure Thyleaf , ViewResolver, ResouceHandler, MessageSource etc
  4. Register AppConfig.class and WebMvcConfig.class  and with AbstractAnnotationConfigDispatcherServletInitializer
  5. Create a JPA Entity and Spring Data JPA Repository
  6. Create a SpringMVC Controller
  7. Create a thymeleaf view /WEB-INF/views/index.html to render list of BaseEntities

Developing Web Application using SpringBoot
  1. Create a Maven based SpringBoot Project
  2. Configure datasource/JPA properties in application.properties
  3. Straight away jump to creating Entity , EntityRepo & Controller
  4. Create Thyleaf view
  5. Create Spring Boot entry point.
 What Are The Advantages ?
Spring Boot lets the developer focus on the application’s development first, and removes the need to be overly concerned with every other aspect of its lifecycle, including deployment and management 
It is easy to create stand-alone, production-grade Spring based Applications that you can ‘just run’”. It supports “convention over configuration”.
  1. Easy Dependency Management
    • Pulls in dependency like springboot-starter-web dependency by default it will pull all the commonly used libraries while developing Spring MVC applications such as spring-webmvc, jackson-json, validation-api and tomcat. 
    • Similarly can see Spring-boot-starter-data-jpa dependency
  2. Auto Configuration
  3. Embedded Server
    • spring-boot-starter-web which pull the spring-boot-starter-tomcat automatically
Apart from the above following are noteable features
  1. Actuators
  2. Dev Tools


Bill Of Material : BOM
Spring  Boot calls its 'intelligent collection of dependencies' as BOM
Spring Developers have taken the time to match all the correct versions that work well with each other.
For Example : if you  are using 'spring-core 4.2.3' then it works well with 'logback-core 1.1.3'. If you keep including dependencies manually then you may have to spend a fair amount of time. Thanks to Spring boot (Maven) all of this is gone.

Note in traditional Spring boot app you use
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>4.2.4.RELEASE</version>
  </dependency>

but in Spring boot you use
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

Reason being... Spring boot starter parent at start or pom takes care of it
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.1.RELEASE</version>
 </parent>




You can change it as you want and the effective pom will change accordingly.





No comments: