A quick tutorial for middleware products

Monday, April 8, 2019

On April 08, 2019 by Kamlesh   1 comment
What does spring framework do?
Spring framework lets you develop java j2ee applications in a rapid easy way,Simple right.
But the problem is setting up spring project manually as it involved lot of configurations.

What does spring boot do?
Spring boot aims to wrap all the spring components in a convenient way with no external xml configuration whatsoever. so basically spring boot lets you create a microservice that wraps the spring core in an easy way.

If you create a spring boot project using spring intializr or in any other way, you will see below maven dependency in pom.xml file which downloads all the spring core components that is required to develop an application,you don't need to add manually each component in the project as you do in manual set up of spring framework.


Components like springs core, hibernate validators, logging etc will be downloaded.


<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.1.RELEASE</version>
</parent>

 
Since above dependency is a parent, all the other dependencies will be treated as child, No need to mention the version of any child dependencies you are going to add, compatible child dependencies are added based on the parent version.

This is a huge advantage of spring boot over manual set up of springs framework, Just imagine manually adding all the dependencies that needs to be compatible to all other existing dependencies, we have all suffered that pain.

Typical spring boot pom would look as shown below

<?xml version="1.0" encoding="UTF-8"?>
<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.spring.security.demo</groupId>
 <artifactId>SpringSecurity</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <packaging>jar</packaging>

 <name>SpringSecurity</name>
 <description>Demo project for Spring Boot</description>

 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.0.1.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
 </parent>

 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  <java.version>1.8</java.version>
 </properties>

 <dependencies>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>

  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.security</groupId>
   <artifactId>spring-security-test</artifactId>
   <scope>test</scope>
  </dependency>
 
  <dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>jstl</artifactId>
  </dependency>
  <!-- To compile JSP files -->
  <dependency>
   <groupId>org.apache.tomcat.embed</groupId>
   <artifactId>tomcat-embed-jasper</artifactId>
   <scope>provided</scope>
  </dependency>
 
 </dependencies>

 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
  </plugins>
 </build>


</project>
In addition to that, Spring boot provides Spring Boot Data JPA which helps in quering with database in a much easy and quick way, See how it is here


Feature Spring Framework Spring Boot
Configuration XML(lot of pain) Annotations(No pain buddy)
Server Need External Server Comes with Embedded Server
ORM Hibernate Spring Boot Data JPA
Actuator Supported Works well with spring boot
Controller Only Web Web and Rest
Do not consider above table as comparison, try to consider as advantages of spring boot over spring framework.

Conclusion
Spring framework was introduced to make it easy for developers to develop an application in short period of time using spring components that will help in focusing more on business logic rather than DAO layer or Controller.

But it involved many problems like manual setup that involved a lot of configuration,persisting mechanism was not very quick and needed some kind of knowledge on hibernate etc.

And Spring boot was introduced to make it much more easy for developers by removing manual setup,removing configuration and introducing spring boot jpa for persisting mechanism.

Note: Spring Boot acts as a container for spring components(spring framework) with very minimal configuration and with lots of other advantages.

1 comment:

  1. If you're attempting to burn fat then you certainly have to get on this totally brand new custom keto plan.

    To create this keto diet service, certified nutritionists, fitness trainers, and top chefs have united to develop keto meal plans that are powerful, painless, cost-efficient, and delightful.

    From their first launch in early 2019, 1000's of people have already completely transformed their figure and well-being with the benefits a good keto plan can give.

    Speaking of benefits: clicking this link, you'll discover 8 scientifically-proven ones offered by the keto plan.

    ReplyDelete