Sitemap

What is Spring?

2 min readJun 7, 2024

--

Spring Framework is a popular open-source framework for building enterprise applications in Java.

The first version of Spring, released in October 2002, was introduced as a lightweight alternative to J2EE. It provided a simpler and more flexible approach to enterprise Java development.

Problems with J2EE that Spring solved

The Spring Framework addressed several key issues and limitations associated with J2EE. Here are some of the main problems with J2EE that Spring effectively solved:

Heavyweight Container

EJB followed an all-or-nothing approach, where developers must adopt the entire EJB framework rather than selectively choosing components or features. This made the EJB container heavyweight and less flexible.

Get Nishchay Anand’s stories in your inbox

Join Medium for free to get updates from this writer.

Spring introduced a more lightweight and modular ecosystem, splitting each concern into separate sub-frameworks (e.g., Spring MVC for web applications, Spring Data for data access). Spring's architecture allowed developers to pick and choose the specific services they needed for their application, significantly reducing the overhead and complexity associated with the traditional J2EE container.

Verbose Deployment Descriptors

With J2EE, the developers had to learn and manage separate configuration mechanisms for both web and EJB components.

Spring took a different approach by introducing a unified configuration style. This consistency meant developers only needed to learn one approach for configuring various components (resources, middle-tier objects, web components).

NOTE: While Spring offers a unified approach, it doesn’t restrict developers to a single file. They can split configuration across multiple files for better organization, allowing for flexibility and control over the configuration process.

Restrictive Programming Model

Each EJB required creating a component interface, a home interface, and a bean implementation class. The EJB container would generated the additional classes required to handle functionalities like lifecycle management during deployment. Additionally, the EJB container offered no support for managing relationships between EJBs. We had to perform JNDI lookups within an EJB to access to another EJB. This introduced extra complexity and boilerplate code in the EJB implementation, making the overall codebase larger and harder to maintain.

Spring simplified this process by using POJOs (Plain Old Java Objects) and dependency injection (DI), eliminating the need for the complex interface and class structures required by EJBs. With Spring, developers could create simple POJOs to encapsulate business logic and then wire them together using DI, which significantly reduced the number of required classes and interfaces.

Additionally, Spring’s Aspect-Oriented Programming (AOP) provided a declarative way to handle cross-cutting concerns (aspects) like transaction management, security, and logging without needing to generate additional classes. This approach kept the codebase smaller, more maintainable, and easier to understand.

NOTE: Spring uses a technique called “weaving” at runtime to apply the aspects to POJOs. This weaving process intercepts method calls or other events within the POJOs and inserts the logic defined in the aspects at the appropriate points (no additional code is generated or added directly to POJOs).

--

--