Welcome to my Spring Boot repository! This repository documents my daily learning journey and hands-on practice with Coder Army.
- Author: Alok Rana
- Goal: Master Spring Boot framework and build scalable backend applications.
- Tech Stack: Java 25, Spring Boot 4.x, Apache Maven, IntelliJ IDEA
- History of Spring Framework & problems with EJB
- Core Java vs Spring Boot (Console vs Web Server)
- Why Spring Boot: Inbuilt Embedded Tomcat, Starter Dependencies, Auto-Configuration
- Anatomy of
@SpringBootApplicationand Component Scanning - Creating first REST API with
@RestControllerand@GetMapping - Configuring application port (
server.port=9090) - Running and testing endpoints (
/hello,/age)
- What is a Build Tool & why Maven is used
- Understanding
pom.xml: GAV Coordinates (groupId,artifactId,version) - Starters & Transitive Dependencies
- Dependency Scopes (
compilevstest) - Maven Wrapper (
mvnw) for standalone builds
- Tight Coupling vs Loose Coupling (Why IoC is needed)
- Hands-on implementation:
NotificationServiceinterface withEmailService,SmsService, andPopupService - Constructor Dependency Injection in
OrderService
- Managing beans via Spring's
AnnotationConfigApplicationContext - Configuration & Component Scanning (
@Configuration,@ComponentScan) @Component(Automatic discovery) vs@Bean(Explicit object creation)- Creating Parameterized Beans via
@Beanmethod (Usermodel initialized with custom state) - Constructor Injection using
@Autowired - Custom Qualifier naming (
@Qualifier("Sms"),@Qualifier("pop"),@Qualifier("Email"))
- Understanding Circular Dependency loops (
OrderServiceβPaymentService) - Diagnosing
BeanCurrentlyInCreationExceptionduring Constructor Injection - Breaking the circular reference cycle:
- Approach 1: Field Injection (
@Autowired) via two-phase bean lifecycle - Approach 2: Constructor Injection with
@Lazyproxy injection
- Approach 1: Field Injection (
- Understanding Spring Bean Scopes:
@Scope("singleton")vs@Scope("prototype") - Eager vs Lazy Loading:
- Default Singleton behavior (Eagerly instantiated at container startup)
- Applying
@Lazyon Singleton beans to defer instantiation until first use - Prototype beans instantiated on demand (Lazy by design)
- Practical demo: Shared
PrinterService(Singleton with@Lazy) vs IsolatedShoppingCart(Prototype) - Understanding why Spring uses
@Lazy(false)instead of a dedicated@Eagerannotation
- Deep dive into Bean Lifecycle phases: Instantiation β Property Injection β Initialization β Active β Destruction
- Modern Annotation-based Lifecycle Callbacks:
@PostConstructand@PreDestroy - Constructor vs
@PostConstruct: Why initialization logic belongs in@PostConstruct(dependencies arenullat constructor time) - Graceful shutdown and resource cleanup via
context.close() - Core architectural differences: Traditional Spring vs Spring Boot (Auto-configuration, Embedded Tomcat, Starters)
.
βββ src/
β βββ main/
β β βββ java/com/example/demo/
β β β βββ _di_ioc/ # Spring IoC Container & Dependency Injection
β β β β βββ BeanLifeCycle/ # Day 8: Bean Lifecycle (@PostConstruct & @PreDestroy)
β β β β β βββ ConfiApp.java
β β β β β βββ DatabaseConnection.java
β β β β β βββ DatabaseService.java
β β β β β βββ Main.java
β β β β βββ circulardependency/# Circular Dependency & Resolution via Field Injection
β β β β β βββ AppConfig.java
β β β β β βββ OrderService.java
β β β β β βββ PaymentService.java
β β β β β βββ Main.java
β β β β βββ beanscopes/ # Bean Scopes (Singleton vs Prototype)
β β β β β βββ AppConfig.java
β β β β β βββ PrinterService.java # @Scope("singleton")
β β β β β βββ ShoppingCart.java # @Scope("prototype")
β β β β β βββ Main.java
β β β β βββ user/
β β β β β βββ User.java # POJO model created via @Bean
β β β β βββ AppConfig.java # @Configuration, @ComponentScan, @Bean
β β β β βββ EmailService.java # @Component, @Primary, @Qualifier("Email")
β β β β βββ SmsService.java # @Component, @Qualifier("Sms")
β β β β βββ PopupService.java # @Component, @Qualifier("pop")
β β β β βββ NotificationService.java # Interface
β β β β βββ OrderService.java # @Component, @Autowired
β β β β βββ Main.java # IoC Container runner
β β β βββ DemoApplication.java # Spring Boot entry point
β β β βββ HelloController.java # Day 2 REST controller
β β βββ resources/
β β βββ application.properties # Configuration (server.port=9090)
β βββ test/ # Unit tests
βββ pom.xml # Maven dependencies & plugins
βββ README.md
β Updated daily with each topic covered!