Giter Club home page Giter Club logo

simple-springboot-webapp-monolith's Introduction

simple-springboot-webapp-monolith

First of all watch below short video on the Spring boot internals


spring-boot-internals


This is the same application as https://github.com/mane-ashok/simple-spring-webapp-monolith with the spring boot. Please refer to its https://github.com/mane-ashok/simple-spring-webapp-monolith/blob/main/README.md for the application details.(DRY principle)

Intent - compare spring application with the spring boot application and understand the difference and how spring boot eases the development

Lets list the differences between the spring and spring boot projects

AreaDifference
Dependency Management and packagingIt's really a cumbersome and time consuming to find out the required dependencies and compatible versions, you must have spent a lot of time figuring it out :). Spring boot makes it easy to add the dependencies via spring initializer (https://start.spring.io/), it has a curated list of dependencies along with the compatible versions which is taken care in the parent project (spring-boot-starter-parent).

Each starter dependency in the spring boot pom.xml file encapsulates set of required dependencies, and you will see less dependencies in the pom.xml. Another notable difference is that the dependency versions are not mentoned in your spring boot pom.xml file and they are inherited through the parent project and you don't have to worry about it. If you are curious to know all the encapsulated dependencies and versions for your project, go to the pom.xml directory and execute - mvn dependency:tree command.

Spring project uses maven-shade-plugin while spring boot project uses spring-boot-maven-plugin for packaging the single executable jar with all the the dependencies

spring project jar file size is -

image

while spring boot project jar is -

image

Spring project opend jar looks like this -

image

It looks like shade plugin merged all the dependency jars along with application classes/objects together in a single jar

while spring boot project opened jar looks like this -

image

In spring boot jar, spring boot loader classes are inside org folder, BOOT-INF folder has application classess/objects plus all the dependencies in lib folder

Spring project MANIFEST.MF file looks like this -

image

while spring boot MANIFEST.MF is like this -

image

Note: Spring boot jar packaging looks much better than the spring project jar, dependencies are nicely separated. Also, notice the Main-Class and Start-Class in spring boot manifest file. This means when you run spring boot jar the JarLauncher class gets triggered which must be taking care of executing @SpringBootApplication class ( Start-Class) with the required class-path set.



Go and compare both the pom files.(https://github.com/mane-ashok/simple-spring-webapp-monolith/blob/main/pom.xml & https://github.com/mane-ashok/simple-springboot-webapp-monolith/blob/main/pom.xml)

Auto configuration Once you have all the dependencies in place, in spring application you create your configuration class with @Configuration annotation and define all your required beans. Spring boot adds some value here and tries to figure out what beans your application might need depending upon the dependencies and property configuratoions in application.properties which is called auto configuration in spring boot. This is bit interesting, right? yes it is..:)

In spring project you have 2 configuration classes - https://github.com/mane-ashok/simple-spring-webapp-monolith/blob/main/src/main/java/org/ashok/context/ApplicationConfiguration.java & https://github.com/mane-ashok/simple-spring-webapp-monolith/blob/main/src/main/java/org/ashok/context/WebSecurityConfiguration.java but in spring boot projectyou will see only https://github.com/mane-ashok/simple-springboot-webapp-monolith/blob/main/src/main/java/org/ashok/springboot/context/WebSecurityConfiguration.java

This means all the bean configurations defined in ApplicationConfiguration.java for spring project are taken care by spring boot auto configuration. However, in spring boot project you have additional properties configurations in application.properties as below

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:~/myFirstH2Database
spring.datasource.username=sa
spring.datasource.password=sa
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect

spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.messages.basename=messages
spring.mvc.static-path-pattern=/resources/**
spring.web.resources.static-locations=classpath:/css/,classpath:/images/

Note: Spring application created 86 beans while spring boot created 256 beans, this might add to the memory foot print. You will see all the beans created in the console logs. You may exclude the unnecessary beans in the @SpringBootApplication(exclude={...})

Application launcher class In spring project you will see the https://github.com/mane-ashok/simple-spring-webapp-monolith/blob/main/src/main/java/org/ashok/AppLauncher.java class with some code in it ( go check it out). In spring boot project you have very simple java class class to launch the application - https://github.com/mane-ashok/simple-springboot-webapp-monolith/blob/main/src/main/java/org/ashok/springboot/SimpleSpringbootWebappMonolithApplication.java with @SpringBootApplication annotation, behind the scene the spring boot must be taking care of functionality/code like that of AppLauncher.java class in spring project, right?
Any other major difference? There is no other major difference in these 2 projects, go check it out :)

simple-springboot-webapp-monolith's People

Contributors

mane-ashok avatar ashok-mane avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.