Spring Core Concepts: Foundation of Spring Framework

Vijayasankar Balasubramanian
6 min read1 day ago

--

Table of Contents

1. Introduction to Spring Framework

2. Overview of Spring Core

3. Dependency Injection (DI)

• Types of Dependency Injection

• Constructor Injection

• Setter Injection

• Field Injection (Not Recommended)

• Using @Autowired Annotation

• Using XML Configuration for DI

4. Bean Lifecycle and Scope

• Bean Instantiation and Initialization

• Bean Destruction

• Understanding Bean Scopes

5. Spring Configuration

• Java-based Configuration (@Configuration and @Bean)

• XML-based Configuration

• Annotation-based Configuration

6. ApplicationContext and BeanFactory

• BeanFactory vs ApplicationContext

• Commonly Used ApplicationContext Implementations

7. Aspect-Oriented Programming (AOP) in Spring Core

• Cross-cutting Concerns

• AOP Concepts (JoinPoint, Advice, Aspect, Pointcut)

• Implementing AOP with Spring

8. Event Handling in Spring Core

• Built-in and Custom Events

• Event Listeners

9. Spring Expression Language (SpEL)

• Using SpEL in Bean Definitions

• SpEL Operators and Functions

10. Integration with Java EE Technologies

• JDBC with Spring

• ORM Integration (Hibernate, JPA)

11. Conclusion

12. References

1. Introduction to Spring Framework

Spring is one of the most widely used frameworks in Java development, providing a robust programming and configuration model for building enterprise applications. Initially developed to address the complexities of Java Enterprise Edition (JEE), Spring has grown into a comprehensive ecosystem, covering web development, data access, security, and cloud-based microservices.

At its core, the Spring Framework revolves around Spring Core, which provides fundamental features like Dependency Injection (DI) and Aspect-Oriented Programming (AOP). These concepts help developers write loosely coupled, maintainable, and testable code.

This essay delves into the essential concepts of Spring Core, explaining the principles, configuration methods, and real-world examples that make Spring a powerful tool for Java developers.

References:

• Johnson, R., Hoeller, J. (2004). Expert One-on-One J2EE Design and Development. Wrox Press.

• Spring Framework Documentation: https://docs.spring.io/spring-framework/docs/current/reference/html/

2. Overview of Spring Core

Spring Core is the foundation of the Spring Framework. It includes the following key components:

Core Container: Manages the lifecycle and configuration of Spring beans.

Dependency Injection (DI): Enables object dependencies to be injected at runtime, reducing tight coupling.

Aspect-Oriented Programming (AOP): Helps manage cross-cutting concerns such as logging, security, and transactions.

Event Handling: Provides mechanisms to handle application events effectively.

Spring Expression Language (SpEL): Allows dynamic value assignment within bean configurations.

Spring Core is implemented using interfaces and classes in the org.springframework.beans and org.springframework.context packages, ensuring flexibility and extensibility.

References:

• Sharma, A. (2018). Spring 5 Design Patterns. Packt Publishing.

• Deinum, M., Long, J., Rubinger, K. (2017). Spring Framework Essentials. O’Reilly Media.

3. Dependency Injection (DI)

What is Dependency Injection?

Dependency Injection (DI) is a design pattern that facilitates loose coupling between objects. Instead of objects creating dependencies internally, the dependencies are injected externally via constructors, setters, or fields.

Spring’s IoC (Inversion of Control) container automatically resolves dependencies and manages object lifecycles, making applications easier to maintain and test.

Types of Dependency Injection in Spring

Spring provides multiple ways to implement DI:

• Constructor Injection

• Setter Injection

• Field Injection (Not Recommended)

Constructor Injection

In Constructor Injection, dependencies are provided through a class constructor.

Example:

@Component
public class Engine {
private String type;

public Engine(@Value("V8") String type) {
this.type = type;
}

public String getType() {
return type;
}
}

@Component
public class Car {
private final Engine engine;

@Autowired
public Car(Engine engine) {
this.engine = engine;
}

public void start() {
System.out.println("Car is running with engine: " + engine.getType());
}
}

This approach ensures immutability, as the dependency cannot be changed after object creation.

References:

• Fowler, M. (2004). Inversion of Control Containers and the Dependency Injection Pattern. Martin Fowler’s Blog.

• Spring Framework Guide: https://spring.io/guides/gs/constructor-injection/

4. Bean Lifecycle and Scope

Bean Lifecycle

Spring-managed beans undergo several phases:

1. Instantiation – Object creation.

2. Dependency Injection – Dependencies are injected.

3. Initialization – Custom initialization logic via @PostConstruct.

4. Usage – Bean is used in the application.

5. Destruction – Cleanup operations before removal (@PreDestroy).

Example of Bean Lifecycle Methods

@Component
public class MyBean {

@PostConstruct
public void init() {
System.out.println("Bean initialized");
}

@PreDestroy
public void destroy() {
System.out.println("Bean destroyed");
}
}

Bean Scopes in Spring

Spring provides different scopes to define how beans are created and shared:

References:

• Spring Documentation: https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans

• Walls, C. (2014). Spring in Action (4th Edition). Manning Publications.

Version History and Key Differences

Spring Framework 1.0 (March 2004)

The initial release of the Spring Framework introduced the Inversion of Control (IoC) container and Aspect-Oriented Programming (AOP) capabilities. It aimed to simplify Java Enterprise Edition (J2EE) development by promoting good programming practices and reducing complexity.

Spring Framework 2.0 (October 2006)

Version 2.0 expanded upon the core features by introducing a more extensible XML configuration, support for dynamic languages, and enhanced AOP capabilities. This release also saw the introduction of the Spring Web Flow for managing web application page flow.

Spring Framework 2.5 (November 2007)

This version emphasized annotation-driven configuration, reducing the reliance on XML. Annotations such as @Autowired and @Component were introduced, simplifying dependency injection and bean declaration. Additionally, support for Java 6 and Java EE 5 APIs was incorporated.

Spring Framework 3.0 (December 2009)

Version 3.0 brought significant enhancements, including:

• Java 5 Support: Leveraging Java 5 features like generics and varargs.

• Spring Expression Language (SpEL): A powerful expression language for querying and manipulating an object graph at runtime.

• REST Support: Native support for building RESTful web services.

• Java-Based Configuration: Introduced @Configuration and @Bean annotations for configuring beans using Java classes instead of XML.

Spring Framework 4.0 (December 2013)

Key features of this release included:

• Java 8 Support: Compatibility with Java 8, including lambda expressions and the java.time package.

• WebSocket Support: Enabling real-time, bidirectional communication between client and server.

• General Enhancements: Improved core container, enhanced Groovy support, and refined annotation configuration.

Spring Framework 5.0 (September 2017)

This version marked a significant milestone with:

• Reactive Programming: Introduction of the Spring WebFlux module for building reactive web applications.

• Java 8 and 9 Support: Baseline upgraded to Java 8, with support for Java 9 features.

• Core Improvements: Enhancements in the core container, functional programming support, and comprehensive integration with Java 8 features.

Spring Framework 6.0 (November 2022)

Major updates in this release included:

• Java 17 Baseline: Requiring Java 17 as the minimum, leveraging its new features and enhancements.

• Jakarta EE 9+: Transition to the jakarta.* namespace, aligning with Jakarta EE 9 specifications.

• AOT Compilation: Support for Ahead-of-Time compilation, facilitating native image generation with GraalVM.

• Observability: Incorporation of Micrometer for application metrics and observability.

Latest Release: Spring Framework 6.2

As of February 2025, the latest stable release is Spring Framework 6.2.3, released on February 13, 2025. This version builds upon the foundations of 6.0 and 6.1, introducing several noteworthy features:

  1. Enhanced Observability

Building upon the observability improvements in 6.0, version 6.2 integrates more deeply with Micrometer, offering:

• Extended Metrics Coverage: Out-of-the-box metrics for more components, including HTTP clients and database interactions.

• OpenTelemetry Support: Seamless integration with OpenTelemetry for distributed tracing, aiding in performance monitoring across complex systems.

2. Improved Native Image Support

Version 6.2 enhances support for native image compilation with GraalVM:

• Optimized AOT Processing: Reducing build times and improving runtime performance for native images.

• Extended Compatibility: Ensuring a broader range of Spring features and third-party libraries are compatible with native image compilation.

3. Kotlin Coroutines Integration

Deepening support for Kotlin, Spring Framework 6.2 offers:

• Coroutine-Friendly APIs: Simplifying the development of non-blocking applications using Kotlin coroutines.

• Flow Support in WebFlux: Enabling the use of Kotlin’s Flow API within Spring WebFlux for reactive data streams.

4. Configuration Enhancements

To improve developer experience and application maintainability:

• Centralized Configuration Management: Introduction of a unified configuration interface, allowing for consistent management of properties across different environments.

• Enhanced Profile Support: More granular control over bean definitions and configurations based on active profiles.

5. Security Updates

Strengthening the security framework:

• OAuth 2.1 Support: Aligning with the latest OAuth specifications, providing improved support for authorization flows and token management.

• Enhanced Password Encoders: Introducing new password

Conclusion

Spring Core provides the essential features of the Spring Framework, enabling Dependency Injection, Aspect-Oriented Programming, and flexible configurations. Understanding these concepts is critical to building scalable, maintainable applications in Java.

--

--

Vijayasankar Balasubramanian
Vijayasankar Balasubramanian

Written by Vijayasankar Balasubramanian

Java Solution Architect, Java Full Stack Engineer

No responses yet