Learnitweb

Category: Spring Core

  • Difference Between @Component, @Service, and @Repository

    1. Introduction In the Spring Framework, all three annotations — @Component, @Service, and @Repository — are used to declare classes as Spring-managed beans. This means: However, each annotation serves a different semantic role within a typical layered architecture.Even though all of them ultimately act as components, they differ in meaning, intent, and sometimes behavior. 2.…

  • Role of CommandLineRunner & ApplicationRunner in Spring Boot

    1. Introduction When a Spring Boot application starts, it goes through several internal phases: Sometimes, you may want to run specific code immediately after the Spring Boot application has started — for example: To handle such cases, Spring Boot provides two functional interfaces: Both are part of the org.springframework.boot package and are commonly used to…

  • BeanFactory vs ApplicationContext in Spring Framework

    1. Introduction In the Spring Framework, one of the core ideas is Inversion of Control (IoC), also known as Dependency Injection (DI). It means that instead of manually creating and managing object dependencies in your code, Spring handles it for you through a container. The container is responsible for: Spring provides two main IoC containers…

  • What is Spring’s BeanPostProcessor? And where it is useful?

    Spring’s BeanPostProcessor is a powerful and fundamental extension point in the Spring Framework’s Inversion of Control (IoC) container. It allows you to hook into the bean lifecycle and perform custom logic on every bean instance created by the container, both before and after its initialization. Essentially, it’s an interface you can implement to intercept the…

  • Why @Transactional Doesn’t Work for Internal Calls in Spring Beans

    This is a classic and very important “gotcha” in Spring’s transaction management. If a method in a Spring bean calls another @Transactional method from within the same bean instance, the transaction annotation on the called method is ignored. Here’s why this happens and what you need to know: The Root Cause: Spring’s Proxy-Based AOP Spring’s…

  • The Difference Between Propagation.REQUIRES_NEW and Propagation.NESTED in Spring

    @Transactional(propagation = Propagation.REQUIRES_NEW) and Propagation.NESTED are two different transaction propagation behaviors in Spring, and they handle nested method calls with transactions in fundamentally different ways. Here’s a breakdown of the key differences: Propagation.REQUIRES_NEW Propagation.NESTED

  • What is the difference between javax @Transactional and Spring framework @Transactional

    The @Transactional annotations from javax.transaction (part of the Java Transaction API – JTA, now part of Jakarta EE) and org.springframework.transaction.annotation (from the Spring Framework) both serve the same fundamental purpose: to declaratively manage transaction boundaries in Java applications. However, they originate from different ecosystems and have distinct characteristics and ideal use cases. Here’s a breakdown…

  • Bean Lifecycle in Spring Boot

    Spring Boot (and Spring Framework in general) manages the lifecycle of beans using the Inversion of Control (IoC) Container, which creates, configures, and manages the entire lifecycle of objects (called beans). Understanding the Bean Lifecycle is essential for developers who want to hook into certain phases of a bean’s existence, such as initialization or destruction,…

  • Spring Bean Scopes

    1. Introduction A bean definition acts like a recipie for creating the actual instances of the the class. You can control dependencies, configuration values and the scope of the objects created from a particular bean definition. The Spring Framework supports six scopes, four of which are available only if you use a web-aware ApplicationContext. You…

  • Java Based Container Configuration

    1. Introduction In this tutorial, we’ll discuss the Java based container configuration in Spring. Two central artifacts in Spring’s Java configuration support are @Configuration annotated classes and @Bean annotated classes. 2. @Bean annotation The @Bean annotation signifies that a method creates, configures, and initializes a new object to be managed by the Spring IoC container.…