I’m Arsalan Mirbozorgi;
Inversion of control container and framework of application for the Java platform are both known as the Spring Framework. Any Java application can use the framework’s core features, but Java EE (Enterprise Edition) developers have access to extensions. It’s a popular addition to the EJB model in the Java community despite not imposing any programming model-specific requirements. The Spring Framework is free to use and modify in any way.
According to Rod Johnson’s book Expert One-on-One J2EE Design and Development, the first version of the framework was made available in October 2002. In June 2003, the Apache 2.0 license for the framework was first made available. The 1.0 production release was made available to the public in March of that year. Jolt productivity and JAX innovation awards were given to the Spring 1.2.6 framework in 2006. After the release of Spring (second version) in October of 2006, Spring 2.5 version in November of 2007, Spring 3.0 version in December of 2009, and Spring 3.1 version in December of 2011, Spring 3.2.5 version was released in November of 2013. As of December 2013, there is a new version of the Spring Framework: 4.0. Support for Java SE (Standard Edition) 8, Groovy 2, and WebSocket were all notable additions in Spring 4.0.
In April 2014, Spring Boot 1.0 was made public.
Immediately after version 4.2.0 of the Spring Framework was released on July 31st, it was upgraded to version 4.2.1 on September 1st, 2015. Java 6 and 7 are supported, but the focus is on core refinements and modern web capabilities.
There will be support for Spring Framework 4.3 until the year 2020. It was released on June 10th, 2016. Spring 4 system requirements (Java 6+, Servlet 2.5+) state that this is the final generation.
Reactor Core, which is compatible with Reactive Streams, will be used in Spring 5.
Modules of Spring Framework
Several modules in the Spring Framework provide a wide range of services:
Containers for Spring are provided by the Spring Core module (BeanFactory and ApplicationContext).
Aspect-oriented programming (AOP) makes it possible to implement solutions that address multiple interrelated problems.
Authentication and authorization: the Spring Security sub-project provides configurable security processes that support various standards, protocols, tools, and practices (formerly Acegi Security System for Spring).
The rapid development of application solutions for Spring-based enterprise applications is available in the Spring Roo module, prioritizing convention over configuration.
Use Java Database Connectivity (JDBC) and object-relational mapping tools to access relational database management systems and NoSQL databases on the Java platform, respectively.
Application configuration and Java object lifecycle management are done primarily through dependency injection in an inversion of control container
Configurable and customizable registration of message listener objects for transparent consumption of messages from message queues via Java Message Service (JMS), enhancement of message sending over standard JMS APIs
An HTTP and servlet-based framework for web applications and RESTful (representational state transfer) Web services, Model–View–Controller provides hooks for extension and customization.
Web services, CORBA, and HTTP-based protocols, such as SOAP (Simple Object Access Protocol), provide a framework for configuring remote procedure calls (RPCs) and marshalling Java objects over networks that support remote method invocation Java.
Coordinates transactions for Java objects by unifying several transaction management APIs.
Configurable exposure and management of Java objects via Java Management Extensions for local or remote configuration (JMX)
Support classes for writing different unit tests and integration tests are available.
Container control inversion (dependency injection)
With its inversion of control (IoC) container at its core, the Spring Framework makes it easy to set up and manage Java objects through reflection. When objects are created, their initialization methods are called, and then these objects are configured by wiring them together in the container.
Container-created objects are also referred to as managed objects or as beans. To configure the container, use XML files loaded from disk or Java annotations detected on configuration classes. The definitions for the beans can be found in these data sources. This information is needed to build the beans.
Either dependency lookup or dependency injection can be used to obtain objects. When a caller requests an object by name or type, the container object follows the dependency lookup pattern. Container-based dependency injection (CCI) is a design pattern in which the container sends objects by name to other objects via constructors, properties, or factory methods.
While using other parts of the Spring Framework does not necessitate the use of the container in many cases, doing so makes it easier to configure and customize an application. The Spring container integrates with nearly all Java environments, from small-scale to large enterprise applications, and provides a consistent configuration mechanism.
The Pitchfork project can partially convert the container into an EJB 3.0 (Enterprise JavaBeans) compliant container. It’s been said that the Spring Framework doesn’t follow standards. In contrast to this, Spring Source claims that the Spring Framework and container allow for more powerful programming models, so EJB 3 compliance isn’t a priority. Instead of creating an object directly, the programmer describes how to do so in the Spring configuration file. A Spring configuration file specifies which services and components must be called rather than calling them directly. The goal of this IoC is to make maintenance and testing easier.
A framework for aspect-oriented programming
Using an aspect-oriented programming (AOP) approach, the Spring Framework‘s AOP framework modularized cross-cutting concerns in aspects using the aspect-oriented programming (AOP) approach. Design, implementation, and configuration should not be overly complex when providing basic AOP features, which is why a separate AOP framework was created. The Spring container is also fully utilized by the Spring AOP framework.
Proxy patterns are used in the Spring AOP framework, which is configured on the fly. No compilation or load-time weaving is required because of this. The only existing objects that can be affected by interception are those that have already been created at a join point.
Spring AOP is less capable than the AspectJ framework, but it is also simpler to use. AspectJ aspects can now be configured in the container thanks to Spring 1.2. For example, the pointcut language can be reused and combined with Spring AOP-based aspects thanks to Spring 2.0’s addition of integration. As a result of Spring 2.0, the Spring Aspects library now offers declarative transaction management and dependency injection via load-time weaving or AspectJ compile-time, as well as other common Spring features. Several other SpringSource projects make use of AspectJ AOP, the most notable of which are the AspectJ-based aspect libraries found in Spring Roo and Spring Insight
In order to work with Spring Framework‘s cross-cutting concerns, Spring AOP was created. Spring AOP can be used to enhance any container-created or -configured object.
AOP is used internally by the Spring Framework for transaction management and security.
Spring provides two ways to configure AOP since version 2.0 of the framework:
schema-based approach and
@AspectJ-based annotation style.
Rather than introducing new terms related to AOP in the Spring reference documentation and API, the Spring team chose to use terms such as aspect and joinpoint that have the same meaning across most other AOP frameworks, like advice and pointcut (particularly AspectJ).
Data access framework
To help developers who struggle with databases in their applications, the Spring data access framework was created. Oracle TopLink (discontinued since 5. x) and Java Persistence API (JPA) are among the popular data access frameworks supported by JDBC, iBatis/MyBatis, Hibernate, and other frameworks such as Java Data Objects (discontinued since 5. x).
This is what Spring has to offer for all of these frameworks it supports:
- Controlling database resources by acquiring and releasing them on demand
- Spring data access hierarchy translation of data access-related exception handling
- Transparent participation in ongoing transactions is referred to as transaction participation.
- Retrieving database objects from connection pool wrappers by performing resource unwrapping
- Dealing with huge objects in a binary or character fashion is facilitated by abstraction.
Spring’s template classes for each supported framework make all of these features available. Some have panned these template classes as obtrusive and not providing any real benefit over using the Hibernate API directly. As a result, the Hibernate and JPA APIs can now be used directly by Spring developers. As application code no longer takes responsibility for obtaining and closing database resources and does not support exception translation, this necessitates transparent transaction management.
Spring’s transaction management and framework of data access run together to achieve a flexible abstraction for working with frameworks of data access. Because there is no common data access API provided by the Spring Framework, the full power of the supported APIs is preserved. Because it is considered the only one available in Java, the Spring Framework provides managed data access environments separate from an app server or a container.
The following beans may need to be configured when using Spring to manage transactions with Hibernate:
Such as a ComboPooledDataSource or an Apache Commons DbCP BasicDataSource, a Data Source
An org.springframework.orm.hibernate-like SessionFactory
Third-party session factory with a DataSource property
A TransactionManager with a SessionFactory attribute similar to org.springframework.orm.hibernate3.HibernateTransactionManager and a HibernateProperties like org.springframework.beans.factory.config.PropertiesFactoryBean
The following items should be configured as well:
There are multiple AOP configurations of cutting points in this image.
AOP advice transaction semantics.
Management of transactions
Java now has an abstraction mechanism thanks to Spring’s transaction management framework. It is capable of the following thanks to its abstraction:
managing transactions on a local and global scale (local transaction does not require an application server)
managing transactions that are nested within transactions
utilizing savepoints in your work
working in nearly all Java platform environments
As a suitable alternative, you can use the Java Transaction API (JTA), but you’ll need an application server to use it (and in some cases also deployment of applications in an application server).
The Spring Framework provides a PlatformTransactionManager for a variety of transaction management strategies:
Java Database Connectivity (JDBC) Transactions
JTA TransactionManager and UserTransaction Transactions handled on other resources, like object databases, Transactions managed on Object-Relational Mapping Units of Work
In addition to this abstraction mechanism, the framework offers two methods for integrating transaction management into applications:
Technically, by using Spring’s TransactionTemplate Metabolically, by using XML or Java annotations (such as @Transactional)
To set up a transactional system without using JTA or EJB with Spring’s data access framework, which integrates the transaction management framework. Messages and caching engines are also integrated with the transactional framework.
Juergen Hoeller presents on Spring MVC/Web Reactive.
Model–view–controller (MVC) web application frameworks were not originally planned for the Spring Framework. The Jakarta Struts Web framework and other frameworks available at the time had poor design, which prompted the Spring developers to write their own. It was felt that the presentation and request handling layers and the request handling layer and model were not sufficiently separated.
Spring MVC is also a request-based framework, like Struts. A modern request-based framework must be able to handle all of these responsibilities, so the framework defines strategy interfaces for them. In order to make it as simple and clear as possible for Spring MVC users to write their own implementations, each interface has been designed with this goal in mind. MVC makes it possible to write cleaner front-end code because of its architecture. The Servlet API forms the backbone of all interfaces. Some people view Spring’s close relationship with the Servlet API as a failure to provide a high level of abstraction for Web-based applications. As a result, developers can still use the Servlet API’s features while also benefiting from a high abstraction framework that makes working with it easier.
As the framework’s front controller, DispatcherServlet is in charge of delegating control to various interfaces as an HTTP request executes.
The following is considered a list of the most important Spring MVC interfaces and their corresponding responsibilities:
Incoming requests are managed and directed to proper responses by the Controller, which sits in between the Model and the View. Using the Controller, the HTTP request will be mapped to the appropriate method calls. It serves as a doorway through which incoming data is channeled. It alternates between going into model mode and viewing the model from a different perspective.
Application: handling incoming requests through the use of an application-specific handler adapter
Incoming request interception is similar to, but not identical to, that provided by Servlet filters by HandlerInterceptor (optional and not controlled by DispatcherServlet).
select objects that deal with requests coming in (handlers) based on any attribute or condition associated with those requests, internal or external
UserLocaleResolver: resolving and saving a user’s locale information
MultipartResolver: wraps incoming requests to make working with file uploads easier
View: in charge of sending a response back to the client after receiving a request. Some requests will be sent directly to the model part, while others will be sent through all three steps.
Resolves views by looking at their names in the object’s property list.
As you can see, each of the strategies mentioned above interfaces, plays an important role. Because these interfaces provide powerful abstractions, Spring MVC ships with implementations of all of them to allow for various implementation variations. This provides a feature set on top of the Servlet API. Developers and vendors, on the other hand, are free to come up with their own solutions. The Java java.util package is used by Spring MVC. Model’s Map interface serves as a data-oriented abstraction for keys, which typically string values, according to the specification.
Spring MVC’s high level of abstraction appears to benefit from making it easier to test the implementations of these interfaces. Spring’s inversion-of-control container uses DispatcherServlet to configure the web layers of the application. On the other hand, Web applications can choose to use other parts of the Spring Framework, such as the container, instead of Spring MVC.
A workflow of Spring MVC
Spring DispatcherServlet receives a request from a web browser when a link is clicked, or a form is submitted. Spring MVC’s DispatcherServlet is a front-end controller. In order to do this, it looks up handler mappings in a database. The request is forwarded to DispatcherServlet, which has been selected as an appropriate controller. The Controller is in charge of processing each request and producing a corresponding result. Model is the term used to describe it. Formatting the data in HTML or a front-end technology like JSP is necessary for it to work. This is how an application’s View looks like. The MODEL and VIEW objects contain all of the relevant data. When the controller and view are not linked, DispatcherServlet uses ViewResolver to locate the actual JSP.
Web.xml must contain a configuration for DispatcherServlet.
Remote access framework
RPC (remote procedure call)-based technologies are available on the Java platform for both client connectivity and marshalling objects on servers. Spring’s Remote Access framework is considered an abstraction for working with these technologies. This framework’s most valuable feature is its ability to combine inversion of control with AOP to make configuring and using these technologies as simple as possible.
Besides fault-recovery, the framework also offers optimizations for client-side use of EJB remote stateless session beans (such as automatically reconnecting after a connection failure).
This set of protocols and products are already supported by Spring by default.
protocols that use the HTTP protocol
open-source binary serialization protocol based on CORBA that’s called Hessian.
Method invocations that use RMI infrastructure but are specific to Spring RMI (2): method invocations that make use of RMI interfaces in accordance with standard RMI usage
Calling methods in CORBA Enterprise with the RMI-IIOP protocol Integration of a JavaBean client
Connecting to local stateless session beans in EJB applications
Using stateless session beans in an EJB application over the internet
CXF integrates with the Spring Framework for server-side RPC exporting objects via SOAP and Apache Axis Web services framework.
With the exception of the Apache Axis support, the Spring Core container configures both client and server setup for all RPC-style protocols supported by the Spring Remote access framework.
There is an alternative open-source implementation for a remoting subsystem in Spring Framework (Cluster4Spring) designed to support different remote schemes (1-1, 1-many, dynamic services discovering).
Rapid application development based on convention rather than configuration
For more information, please see: rapid development of application
When it comes to creating “just run” Spring-based applications, Spring Boot’s convention over configuration approach is the way to go. Preconfigured with the “opinionated view” of the Spring team on the best configuration and application of the platform and third-party libraries so that you’ll be able to get started quickly. Spring configuration isn’t necessary for the vast majority of Spring Boot applications.
The following are its distinguishing characteristics:
- Develop Spring standalone applications
- Directly embed Tomcat or Jetty (no need to deploy WAR files)
- Starter project object models can help you get your Maven/Gradle configuration up and running faster.
- Whenever possible, configure Spring automatically.
- Assert metrics, health checks, and externalized configuration as production-ready features.
- There is no need to generate any code or set up any XML configuration.
- Easy integration and support for all Enterprise Integration Patterns are two of the many benefits of this system.
This project, called Spring Roo, uses convention-over-configuration to help developers quickly build Java applications. It relies on code generation instead of configuration to accomplish this. Spring Framework, Spring Web Flow, and Spring Security are all supported. Rapid application development frameworks typically focus on a variety of different aspects of the application.
- The ability to go further (via add-ons)
- Platform productivity on the Java platform (as opposed to other languages)
- Avoidance of all distractions by locking yourself into one position (Roo can be removed within a few minutes from any application)
- Avoidance of occurrences at a later time (with associated deployment advantages)
- Convenience and usability (particularly via the shell features and usage patterns)
Spring Batch provides reusable functions that are critical for handling large volumes of records as a batch processing framework.
Management of transactions by logging and tracking
Statistics of work in progress work resumption
As a bonus, it offers more advanced technical services and features that make it possible to run extremely large batch jobs at high speeds while maintaining high-efficiency levels. When using Spring Batch, you can run multiple jobs at the same time. Each job has several steps, each of which is composed of a READ-PROCESS-WRITE task (tasklet).
Data is read from a resource (comma-separated values (CSV), XML, or database), processed, and then written to other resources in the “READ-PROCESS-WRITE” process. process (CSV, XML, or database). Processor steps can process and write data to the database by reading data from a CSV file. Using Spring Batch, you can read and write CSV, XML, and database data.
It means doing only one thing, like cleaning up the resources before or after a step starts or finishes, for a “single” operation task (tasklet).
It’s possible to create a job out of these steps.
Reusable functions for messaging or event-driven architectures are provided by Spring Integration, a framework for enterprise application integration.
Message channels are routed to by routers when certain conditions are met.
To implement with other technologies and systems (HTTP (Simple Mail Transfer Protocol), AMQP (Advanced Message Queueing Protocol), JMS (Java Message Service), XMPP, IMAP, FTP, and FTPS/SFTP, file systems, etc.) transformers – convert, transform, or change the message payload and creates a new message with transformed payload adapters.
Filtering – a message is filtered according to certain criteria. A service activator invokes an operation on a service object management and auditing when certain criteria aren’t met.
Spring Integration supports Pipe-and-filter architectures.