SPRING / NOTES</>↗Spring02 Jul 2026
Use constructor injection by declaring your dependency as a private final field and accepting it as a constructor parameter. Spring will create the dependency bean and pass it into the constructor automatically. Example: import org.springframework.stereotype.Component; @Component public class MyDependency { public void doSomething() { System.out.println("Dependency logic executed."); } } import org.springframework.stereotype.Service; @Service public class MyService […]
SPRING / NOTES</>↗Spring02 Jul 2026
Short Answer Use these annotations according to the role of the class: Annotation Use for Typical layer @Component Generic Spring-managed class Utility/infrastructure/helper @Service Business logic Service layer @Repository Data access / persistence Repository/DAO layer All three make the class a Spring bean, meaning Spring can create it, manage it, and inject it into other beans. […]
SPRING / NOTES</>↗Spring02 Jul 2026
The Spring ApplicationContext is the central runtime container of a Spring application. In simple terms: ApplicationContext is the object that holds your Spring application together. It knows: which objects Spring should manage how those objects are created how dependencies are injected which configuration values are available which beans need lifecycle callbacks which features like transactions, […]
SPRING / NOTES</>↗Spring02 Jul 2026
Component scanning is how Spring automatically finds your classes and registers them as beans. Instead of manually creating every bean, you annotate classes with Spring stereotypes like: @Component @Service @Repository @Controller @RestController Then Spring scans selected packages, finds those classes, creates bean instances, and makes them available for dependency injection. 1. Basic Example import org.springframework.stereotype.Service; […]
SPRING / NOTES</>↗Spring02 Jul 2026
Spring Java configuration lets you configure your application using Java classes instead of XML. The main annotations are: @Configuration — marks a class as a Spring configuration class @Bean — declares a Spring bean manually @ComponentScan — tells Spring where to find annotated components @PropertySource — loads external properties @Enable… annotations — enable specific Spring […]
SPRING / NOTES</>↗Spring01 Jul 2026
In Spring, a bean is an object managed by the Spring container. Spring is responsible for: creating the object injecting its dependencies managing its lifecycle applying configuration destroying it when the application shuts down The container that manages beans is usually the ApplicationContext. 1. What Is a Spring Bean? A Spring bean is just a […]