Spring Ecosystem : Spring Framework family

 Spring Framework - Ecosystem and Overview

  •  When people refer spring, they refer to the entire spring eco-system of projects like spring framework, spring boot, spring data, spring cloud, spring batch and a whole lot more of other projects.
  •  Spring came to existence in response to J2EE to make development and data access a lot easier. It also aimed at reducing boiler plate code(Repetitive code which needed often and clutters the application and draw focus of the main logic ).
  •  Success of the spring framework led to the creation of other spring projects which are built on the top of it.
  •  Example - spring data makes data access easier. Spring security handles security aspects of java application.
  •  Spring boot is a real game changer. Up until spring boot, creating a spring application involved a lot of choice making, configuration and cumbersome deployment model.
  •  Spring boot removed all of the boring boring aspects of spring and included sensible auto-defaults of library choices, configuration and stubs for auto-detecting and adding common configutation.
  •  It also made the deployment process a lot easier as running a simple command.
  •  Spring cloud was built on the top of spring boot and simplifies building applications which make use of distributed architectures. 


 Why Spring?

  •  Initially, it just started out to address the complexity of J2EE. But now, it is much more than that. It is an alternative to J2EE. Application creation is very hard and spring makes it easier to create java enterprise applications.
  •  Spring is flexible, modular and backwards compatible.
  •  Spring has large and active community. 
  •  Spring continually evolves and innovates. 



 Spring Framework vs Spring boot

  •  Spring boot makes it easy for developers to learn it in a quick and easy manner. 

 Notable Features

    • Auto-configuration 
    • Stand alone - do not need to deploy to webserver. Just run it with a command.
    • Opinionated - default settings are opinion of majority.

  Auto-configuration

    •  Attempts to automatically configures your spring boot application based on the features you have added.
    •  Auto-configs are contextually aware and smart. Eg. If the application has dependency of a database, it attempts to configure application for the database access.
    • Setting up auto configuration is easy. Just add @EnableAutoConfiguration annotation.  Think of annotations as extra code, read at run time to make decisions.
    • Also, the configurations are also easy to disable.

  Stand-alone

    • According to spring boot project, _" Spring boot makes it easy to create standalone,  production grade spring based applications that you can just run "
    •  To understand the importance of above statement, we need to understand how normal java applications run namely.
    • Packaging your application
    • Downloading the webserver - different choices with different features.
    • Once decided, download and configure the web server. Depending on the server, can be complex or simple.
    • Last, deploy the application (Copy to a specific directory) and start web-server.      

 Opinionated view

    • It is not a bad thing. When building java applications, we have a tons of choices like logging choices, config choices, tooling choices and build tool choices and so on.
    • If a developer is new, it can be overwhelming. So, springboot favours convention over configuration to get an application up and running as quickly as possible.
    • Opinionated here means - established standards and popularity.
    • A developer can overwrite any of the choices anytime.

     spring initializr is a great example of spring boot opinionated set up. You can just give what kind of configurations you need in dependencies and it provides popular choices.



 Software Framework 

  •  Spring Framework is a software framework. But what is a software framework? It is a universal, reusable software environment meaning the software can be used and re-used anywhere and it serves as a support on which applications are built.
  •  A Software framework must provide a particular functionality. Spring helps in web development and data access.
  •  A software framework doesn't exist on its own. It is part of something else.
  •  A software framework facilitate development of software applications, products and solutions. 


 Spring Framework

 Spring framework is divided into six key areas. 

  •  Spring Core
  •  Spring Web
  •  AOP (Aspect Oriented Programming)
  •  Spring Data Access
  •  Spring Integration
  •  Spring Testing

    

 Spring Core

  • Spring core is the most important module of the spring framework. The other modules are built on the top of it.
  • It has a lot of other features. However, at the center of spring core is Dependency Injection.
  • In Object Oriented Programming, we model real world entities to object. Suppose, we have a Computer class which has dependencies like Memory Object and Hard disk Object.

  

public Class Computer{
    Memory memory;
    HardDisk hardDisk;
}


 There are two ways in which we can fulfill these dependencies. 

  •  One, On its own, creating an object and also its dependencies. 
  •  Two, just declaring I need these objects and some external entity providing those objects at run time.     

 Spring Core is a dependency injection container. 

  •  It creates and maintains objects and their dependencies.
  •  This makes less for developer to manage. 



 Spring Web

 Spring Web Module is the framework for handling web requests.

 This can be done in 2 ways

  • Spring Web MVC
  • Spring Web flux

  

Spring Web MVC    

     Understanding Servlet - Java Language introduced a very basic support for interacting with the web via a built-in framework called Servlet API.  It is named after a key component called a servlet. In Simple terms, a servlet is an object which receives a request and generates a response based on that request.

     Challenges 

  • Servlet is a low level API means it is very detailed and offers less way of abstracting complexity. 
  • It means it is harder to use and less productive. The code will get complex with time. 
  • Request/Response <=> Web Server <=> Servlet API <=> Business Logic

     Solution

  • Spring Web Mvc is a higher level API that can be used to interact with the business logic and makes code less complex and more productive.
  •  Request/Response <=> Web Server <=> Servlet API  <=> Spring Web Mvc <=> Business Logic
  •  MVC refers to model - view - controller which is a design principle results in organized and easy to maintain code.

  Spring Webflux

  • Understanding reactive programming - Reactive programming is a declarative programming paradigm concerned with data streams and how they change.
  • Idea behind reactive programming - React rather than wait   
  • New Flow - handle web requests in an asynchronous fashion and they doesn't block or wait which results in better ulitization of resources.
  • Traditional Flow - web request steps are in order and executes one step after other. When one step depends on other, if one step step is blocked, the request is blocked and computing resources tied up to the request are also blocked and cannot execute requests. It is synchronous in fashion.
  • The difference between both is asynchronous, when a request is waiting, if another request comes, the code then tells, do other things and once the request is complete, it will notify.

 

  Spring AOP   

  • AOP - Aspect oriented Programming
  • It is a programming paradigm (a way of writing code)
  • Aims to increases modularity (increases organization)
  • By allowing separation of cross cutting concerns. A cross cutting concern may span across multiple tiers or layers of an application. 
  • Example - Security which cannot be contained to one area of the application.     
  • Without AOP, solving concerns that are cross cutting results in scattered and duplicated code cross many parts of an application
  • Can create an annotation and use that annotation anywhere.

        


  Spring Data access

  • Reduces a lot of boiler plate code and makes it a lot simpler to write database operations.
  • Supports transactions too. 
  • An exception is an event within a program which disrupt execution.
  • Exception translation - different databases can throw different error codes for same violation. Spring data maps them together.
  • Mainly related to data access to relational databases.
  • For other type of databases, checkout the spring data project which is an umbrella project for dataaccess of different projects preserving the database unique features.

       

  Spring Integration

  •  Integration is all about making different systems and applications work together.
  •  It is multi sided problem

    •  How do you expose operations to other systems?
    •  How do you invoke or run operations on other systems?
  • Three options
    • RMI (Remote Method Invocation) - one way
    • Messaging systems    
    • Web Services (Famous)

 

 Spring Projects

There are 22 spring projects active now.  Few of them are
  • Spring boot    - Spring Boot makes it easy to create stand-alone, production-grade spring based Applications that you can "just run". No need of any extra configurations.
  • Spring Data   - Spring Data provides a familiar and consistent, Spring-based programming model for data access while still retaining the special features of the underlying data store.
  • Spring Cloud - Spring Cloud provides tools for developers to quickly build some of the common patterns in distributed systems like configuration management, service discovery, circuit breakers, intelligent routing, micro-proxy, control bus, one-time tokens, global locks, leadership election, distributed sessions, cluster state. Coordination of distributed systems leads to boiler plate patterns, and using Spring Cloud developers can quickly stand up services and applications that implement those patterns. They will work well in any distributed environment, including the developer’s own laptop, bare metal data centres.
  • Spring Security - Spring Security is a powerful and highly customizable authentication and access-control framework which is the de-facto standard for securing Spring-based applications.
  • Spring Batch  - A lightweight batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems.

Links


Post a Comment