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)