Why Spring Framework

Spring Framework is one of the most popular Java frameworks, but why is that? 

Fist of all, we know that using a framework is mandatory when we start a complex (or not so complex!) project, especially to avoid wasting our time on conditioning repetitive tasks or environmental issues that are already solved in a framework, and invest our time in what really matters, our project core development. 

Discover the world of Open-Source and all the various possibilities that it offers, based on open exchange, which gives developers plenty of benefits.

Spring provides us with a complete platform for java applications. It handles all infrastructure, and it is like the glue to every application component. Hence, it manages the life cycle and interaction between them.

Frameworks are made with lots of knowledge achieved over the years and continue evolving:

  • they include a variety of design patterns
  • apply industry standards
  • and force us to develop in a certain way (that is an advantage, of course!)

So, what about Spring. 

Spring is  

  • lightweight in size and functionality
  • AOP (Aspect-Oriented Programming) is a powerful tool that is used to increase modularity by allowing the separation of cross-cutting concerns like logging, security, etc

As well, Spring is divided into modules, which is so helpful when we need to define the solution application architecture. 

Some of them are:

    •  Core:
      • Dependency Injection (DI)
        • one of the main Spring functionalities!!!
        • ensures loose-coupling between the classes
  • Validations
        • with annotations and classes, through which we can get the errors raised by bean Validator implementation. You can pass an object of a class into a Validator, and it checks if the constraints are satisfied.
  • Databases
      • You can use Spring ORM (Object Relational Mapping) with Hibernate underneath
        • It is a way to represent the database tables with Java objects and vice-versa
      • Spring JPA (Java Persistence API)
        • to define more specific access methods
      • Spring JDBC (Java Database Connectivity)
        • If you have an old JDBC code is the best option. 
        • Furthermore, to call pl/SQL procedures if they didn’t fit the structure that Hibernate requires.
  • Spring Batch
      • It is beneficial when database queries take too long to finish. 
      • Your browser request would die on these situations, and as your web server (like Tomcat ) has a default setting of x minutes for timing out user requests, it would cancel the petition.
      • If we use Spring Batch job in the request, it will only return a job identification and continues working in the background, so the user would not wait for a response, and he can go on with other tasks. 
      • With that job id, we can check the job status and keep the user updated (for example, with an email).
      • It is important to know that Spring Batch is not faster than other tools, but it ensures data consistency and integrity. 

             Web:

      • Spring MVC (Model-View-Controller) 
        • A very used pattern
        • You can use Spring MVC to expose your services as RESTful URLs.
        • In addition, integrate Spring HATEOAS  (Hypermedia as the Engine of Application State), which can help to represent resources. 
          • This concept is really important, and it is when a web service provides a contract to its consumer before they can call it.
          • In SOAP applications, this information is in its interface to the client, in REST applications we provide the URLs but we still need to know what the server expects here.
  • WebFlux
        • It is an asynchronous I/O, a parallel version of Spring MVC, and supports a fully non-blocking reactive stream. 
        • It uses Netty as an inbuilt server to run reactive applications
  • WebSockets
        • A very thin lightweight layer over TCP, a bi-directional, full-duplex, persistent connection between a web browser and a server
      • STOMP (Simple Text Orientated Messaging Protocol)
        • a messaging client for an interactive application
  • WebClient
        • a component that helps us to build reactive and non-blocking web applications
  • Spring Security
      • To secure web applications, there is Spring Security, that intercepts web URLs
      • You can add annotations on java methods to make them secure too.
      • What is more, you can include authentication (who you are) and authorization (what you can do in the system).
  • Integration:
    • JMS (Java Message Service and Integration to Enterprise Java) 
      • It is a Java Message Oriented Middleware used to send messages between clients and works by sending messages to a message queue
    • JMX (Java Management Extension)
      • The automatic registration of any Spring bean as a JMX Mbean
      • A flexible mechanism for controlling the management interface of beans
    • RMI (Remote Method Invocation) 
      • RMI is a mechanism that allows an object residing in one system (JVM) to access or invoke an object running on another JVM. 
      • The remoting support eases the development of remote-enabled services that provides a special remoting strategy which allows Java serialization via HTTP
  • Unit and Integration Testing
  • Mock Objects
        • when writing integration tests with Spring, it can sometimes be convenient to mock Spring bean dependencies
  • Test Fixtures with JUnit
      • It is a fixed state of a set of objects used as a baseline for running tests.
      • The purpose is to ensure that there is a well-known test environment and to have repeatable tests.
    • Context Management and Caching
      • provides consistent loading of Spring Application Contexts and caching of those contexts (this can be very important because startup time can become an issue)
  • Other things you can do
      • create standalone java projects
      • convert your application into an executable
      • integrate Social Media into your project with Spring Social
      • provide a mobile user experience with  Spring Mobile
      • use Bootstrap (Bootstrap is a responsive CSS Framework) and Angular to create the frontend
      • you can use Spring Boot to start the project in minutes with the desired dependencies (https://start.spring.io/)
      • integrate Maven and Gradle 

Discover the world of Open-Source and all the various possibilities that it offers, based on open exchange, which gives developers plenty of benefits.

This summary was only a brief snapshot of what Spring can bring just to help developers to select the best option before starting a new java project, or when upgrading an old one. Some of the most essential features are here, and it was just an effort to highlight the major components, so it is up to you to dig deeper into each subject. 

Spring is pretty easy, and its results are powerful, extensible, and pattern-based. Many large organizations use Spring, and I highly recommend that if you are not using it, please take the first step after reading this and join the community.

 

Menu