DEV Community

Sugumar R
Sugumar R

Posted on

Spring framework basic

βœ… Day 1: Introduction to Spring Framework (FULL DETAILS)

πŸ”Ή What is Spring Framework?

Spring is a Java-based framework used to create enterprise-level applications. It helps you write clean, maintainable, testable, and loosely-coupled code.


🧱 Core Concepts in Spring Framework

Term Meaning

IoC (Inversion of Control) Framework controls object creation, not the developer.
DI (Dependency Injection) Automatically gives required objects to classes.
Bean An object created and managed by Spring container.
ApplicationContext Main container that manages beans.
Spring Container Core part that manages beans and their lifecycle.


🧠 Why Use Spring?

Feature Benefit

βœ… Lightweight Not heavy like other frameworks
βœ… Easy Testing Supports JUnit, Mockito
βœ… Loose Coupling Classes are not tightly connected
βœ… Fast Development Auto wiring, configurations
βœ… Integration Works with JDBC, Hibernate, REST APIs


πŸ“Έ IMAGE: Spring Architecture Diagram

πŸ”— Spring Architecture Source – JavaTpoint


πŸ•°οΈ Old Spring vs New Spring Boot – Full Table

Feature Old Spring Spring Boot

πŸ”§ Setup Manual config using XML Auto-configured with annotations
β˜• Server Need to deploy on external Tomcat Embedded Tomcat built-in
🧾 Config applicationContext.xml file application.properties or .yml
πŸ’» Main Class No default class Uses @SpringBootApplication
🧠 Learning Curve More complex Easier and beginner-friendly
πŸ§ͺ Testing Manual setup JUnit, Spring Test built-in


πŸ“‚ Spring Framework Modules (Core)

Module Description

Core & Beans Handles dependency injection
Context Spring container
Expression Language (SpEL) Dynamic values like math or string
AOP Aspect-Oriented Programming
Web (MVC) For web app development
ORM For integration with Hibernate/JPA
JDBC Simple DB access with less code
Test Unit testing using JUnit/TestNG

πŸ”— Full module diagram


πŸ” Understanding Dependency Injection (DI)

Example:

public class Student {
private String name;

public Student(String name) {
    this.name = name;
}
Enter fullscreen mode Exit fullscreen mode

}

Here, instead of creating Student manually, Spring injects it for you.


πŸš€ Spring Framework Basics in Code

🧾 XML Configuration

🧾 Annotation Configuration

@Component
public class Student {}

🧾 Java Configuration

@Configuration
public class AppConfig {
@bean
public Student student() {
return new Student();
}
}


πŸ“Œ Summary for Day 1

Topic Covered

What is Spring? βœ…
Why use Spring? βœ…
Core Concepts βœ…

Spring Architecture βœ…
Old Spring vs Spring Boot βœ…

Spring Modules βœ…

Simple Code Examples βœ…


πŸ”œ Coming up in Day 2:

Types of Spring Configuration (XML, Annotation, Java-based)

Creating your first Spring app

Using ApplicationContext

What is Bean Lifecycle?

Top comments (0)