Introduction | Spring Framework

Spring Framework • Java Spring

Introduction | Spring Framework

Introduction

The Spring framework is an open-source framework for building enterprise applications. It provides a wide range of features and tools for developing an application in a modular and reusable way. The Spring framework is designed to make it easier to build and maintain Java applications by providing a comprehensive set of features for managing the complexities of enterprise application development.

Spring is a dependency Injection framework to make java applications loosely coupled i.e., it is easy to modify.

Spring Sabaody Archipelagoramework was developed by Rod Johnson in 2003.

Spring framework provides comprehensive infrastructure support for developing Java applications.

It handles the infrastructure so you can focus on your application.

Why Spring Framework?

Spring is a well-established framework with lots of features that help developers to work on their applications rather than worrying about non-functional code because Spring provides all the dependencies related to non-functionality.

Spring framework is lightweight as it doesn't involve installation, start and stop activities associated with a container. It also increased developers' productivity and reduces the application development time. There are several reasons why we need Spring Framework -

  • Inversion Of Control (IoC) and Dependency Injection (DI): Spring IoC container and DI mechanism make it easy to manage the dependencies and lifecycle of an object in an application. This allows for more decoupled and flexible code, as well as easier testing and maintenance.

  • Aspect Orient Programming (AOP): Spring's AOP support allows for cross-cutting concerns, such as logging, security or transaction management, to be separated from the core business logic of the application. This makes the code more modular and easy to understand.

  • Data Access: Spring provides a consistent and powerful framework for working with databases and other data storage systems. This simplifies the process of working with data and makes it easier to change the underlying data storage technology if needed.

  • Transaction Management: Spring transaction management support allows for easy and consistent management of transactions across different data access technologies. This simplifies the process of working with transactions and makes it easier to ensure that the application is properly handling transactions.

  • Web Services: Web Services provide support for building and consuming web services, including RESTful web services. This makes it easy to build web services that can be consumed by a wide range of clients including web browsers and mobile devices.

  • Modularity: Spring provides a modular approach to developing applications, with a wide range of features and modules that can be added as needed. This allows developers to choose the features that are needed for a specific application and avoid adding unnecessary complexity.

  • Community and Support: Spring has been around for more than a decade and has a large and active community of developers. This means that there is a wide range of resources available for learning and working with Spring as well as support for troubleshooting and problem-solving.

  • Integration: Spring can be easily integrated with other technologies and frameworks such as Hibernate, JPA, Struts and others. This allows the developers to take advantage of the best features of each technology and create a powerful and flexible application.

Spring Layered Architecture

Spring follows layered architecture i.e., consists of four layers they -

  1. UI Layer - This layer is also called the presentation layer. This layer is responsible for handling the user interface, such as displaying data to the user and receiving input from the user.

  2. Business Logic Layer - This layer is responsible for implementing the business logic and rules of the application, such as validating inputs and performance calculations.

  3. Data Access Layer - This layer is responsible for accessing and maintaining data such as reading and writing to a database.

  4. Database - This layer is nothing but acts as storage for all the content and information.

This layer allows for more flexibility and modular design as a chance to one layer does not necessarily impact the other layer.

However, a layered architecture can also be more complex and harder to implement. It can be challenging to ensure that the different layers are properly decoupled and the dependencies between them are managed correctly. Additionally, it can lead to a lot of boilerplate code, which can make the application harder to understand and maintain.

In general, a layered architecture is a good choice for medium to large-sized applications and teams that have experience with software development.

Spring Modules

Spring module consists of the Spring framework. It contains all the features provided by Spring such as Spring Core, Spring AOP, Spring Database etc.

Spring Framework - Architecture

Spring Core

This module consists of 4 sub-modules i.e., Core, Beans, Context and Spring Expression Langauge (spEL). They provide core fundamentals to Spring application.

The Core and Beans sub-module contains all the fundamental parts of the framework such as Dependency Injection, Spring IoC etc. These modules (Core & Beans) helps in injecting an object from one class to another.

core

This is the main module that you need for every Spring Application. In this JAR file, you will find all classes that are shared among all other Spring modules (for example, classes for accessing configuration files). Also, in this JAR, you will find the selection of extremely useful utility classes that are used throughout the spring codebase and that you can use in your application.

beans

This module contains all the classes for supporting Spring manipulation of Spring beans. Most of the classes here support Spring beans factory implementation. For example, the classes required for processing the Spring XML configuration file and Java annotation are packed into this module.

sePL

This module contains all support classes for Spring Expression Language. spEL sub-module is a powerful module that is used to manipulate and query the expression language. Expression is nothing but the values of the object at runtime.

context

Meanwhile, the Context sub-module inherits the features from the Bean module and along with that it adds other features such as internationalization propagation, resource loading and the transparent creation of context. It also provides features of JavaEE such as EJB, JNS etc.

This module also helps in the integration of dynamic scripting languages (for example JRuby, Groovy and Beanshell)., scheduling task execution and so on.

Aspect Oriented Programming (AOP)

This module contains all the classes you need to use Spring AOP's feature within your application. You also need to include this JAR in your application if you plan to use other features in Spring that use AOP, such as declarative transaction management.

It allows us to define method interceptors and point cuts through which decouple the code. It helps in separating the code. Interceptors help to invoke some functionality before or after any method we use AOP. In short, AOP helps to decouple the code.

Aspect

This module contains all the classes for advanced integration with the AspectJ AOP library. For example - if you are using Java Classes for Spring Configuration and need AspectJ-style annotation-driven transaction management, you will need this module.

Instrumentation

This module includes a Spring instrumentation agent for JVM bootstrapping. This JAR file is required for using load-time weaving with AspectJ in Spring Application.

Messaging

This module contains key abstractions taken from the Spring Integration project to Serve as a foundation for message-based applications and adds support for STOMP messages. It contains a lot of annotation which is used to map the messages with methods.

Data Integration / Access

The Data Access/Integration layer consists of the JDBC, ORM, OXM, JMS and Transaction modules.

JDBC

This module contains all the classes for JDBC and provides an abstraction layer. You will need this module for all applications that require database access. Classes for supporting data sources, JDBC data types, JDBC templates etc. are packed in this module.

JMS

This module provides Spring's support for the Java Messaging Service. It contains features for both producing and consuming messages.

ORM

ORM stands for Object Relational Mapping. This module extends Springs's standard JDBC feature set with support for popular ORM tools including Hibernate, JDO, JPA and data mapper iBATIS. Many of the classes in this JAR depend on the classes contained in the spring-jdbc JAR file so you need to include that in your application as well.

This module is an integration layer that allows us to use different ORM tools in a single project.

OXM

Stands for Object XML Mapping. Classes for the abstraction of XML marshaling and unmarshalling and support for popular tools such as Castor, JAXB, XML Beans and XStream are packed into this module.

Web MVC

We use this module to create web projects. We use this module to create RESTful applications. It contains Web, Servlet, Portlet and Web Socket.

web

This module contains the core classes for using Spring in your web application. Including classes for loading an ApplicationContext feature automatically, file upload support classes, and a bunch of useful classes for performing repetitive tasks such as parsing integer values from the query String.

Test

Spring provides a set of mock classes to aid in testing your application and many of these mock classes are used within the Spring test suite, so they are well-tested and make testing your application much simpler. Certainly, we have found a great use for the mock HttpServletRequest and HttpServletResponse classes in unit test for our web application

On the other hand Spring provides tight integration framework with the JUnit unit testing framework and many classes that support the development of JUnit test cases that are provided in this module; for example SpringJUnit4ClassRunner provides a simple way to bootstrap the Spring ApplicationContext in a unit test environment.

Did you find this article valuable?

Support Xander Billa by becoming a sponsor. Any amount is appreciated!