Сообщения

IoC:ApplicationContext, BeanFactory. Bean

 Bean - bean is an instance of a class managed by Spring Boot. package com.appsdeveloperblog.ws.demotransaction2; import org.springframework.stereotype. Component ; @Component public class Customer { private String name ; public Customer (String name) { this . name = name; } } package com.appsdeveloperblog.ws.demotransaction2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure. SpringBootApplication ; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation. Bean ; @SpringBootApplication public class DemoTransaction2Application { public static void main (String[] args) { ApplicationContext apc = SpringApplication. run (DemoTransaction2Application. class , args); for (String s : apc.getBeanDefinitionNames()) { System. out .println(s); } } @Bean public String getName () { return "Parvin" ; } } ---- About ap

Entity Lifecycle

Изображение
  1. package com.appsdeveloperblog.ws.demo_transactional; import com.appsdeveloperblog.ws.demo_transactional.entity.Account; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import lombok. RequiredArgsConstructor ; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure. SpringBootApplication ; @SpringBootApplication @RequiredArgsConstructor public class DemoTransactionalApplication implements CommandLineRunner { private final EntityManagerFactory emf ; public static void main (String[] args) { SpringApplication. run (DemoTransactionalApplication. class , args); } @Override public void run (String... args) throws Exception { EntityManager em = emf .createEntityManager(); em.getTransaction().begin(); // Transient mode: because it does not exist in DB Account account = new Account(); // Ma

ACID, Isolation level, @Transactional

Изображение
 1. In general, Spring does not create proxy classes by default for stereotype-annotated classes (such as those annotated with @Component , @Service , @Repository , etc.). Spring only creates a proxy for a class when it needs to apply some kind of aspect-oriented programming (AOP) , typically for features like transaction management, security, or custom-defined interceptors. Here are the conditions under which Spring creates a proxy: AOP Requirements : When there is a specific aspect (e.g., @Transactional , @Cacheable , or @Async ), Spring uses a proxy to implement that aspect without modifying the class itself. Interfaces : If a class implements an interface and Spring needs to create a proxy (e.g., for @Transactional ), Spring will use JDK dynamic proxies by default, which only proxy interfaces. For classes without an interface, Spring uses CGLIB to create a subclass proxy. In the example you provided, B is annotated with @Component , but it doesn’t have any aspect requirements. So