Spring72 [spring 3편] spring @Transaction 동작 원리 목차는 spring series 목차 에 있습니다. 스프링 @Transaction 동작 원리 스프링 @Transactional 의 주된 개념은 AOP proxy 입니다. 여기서 AOP, Proxy 에 관련해서 자세히는 다루지 않겠습니다. 이 부분을 좀 더 상세화 해보면 Spring core 에서 @Transacational 이 붙은 메소드를 찾아서 (AOP mechanism) Proxy Object 를 만듭니다. Proxy object 를 통해 proxy mechanism 이 동작되고, 실제 호출하는 메소드를 감싸서 트랜잭션을 적용하게 됩니다. 정확히는 Proxy Object 은 TransactionInterceptor 를 호출하고, 여기서 트랜잭션 commit, rollback 등을 처리합니다. 스프링.. 2021. 5. 14. spring-data-jpa save 동작 원리 source 는 Github 에 있습니다. spring-data-jpa save 동작 원리 spring-data-jpa save source 를 보면 아래와 같습니다. entity 가 새로 생성할 예정이라면 persist() 를 호출하고, 그렇지 않다면 merge() 를 호출합니다. SimpleJpaRepository.java /* * (non-Javadoc) * @see org.springframework.data.repository.CrudRepository#save(java.lang.Object) */ @Transactional @Override public S save(S entity) { if (entityInformation.isNew(entity)) { em.persist(entity); r.. 2021. 4. 28. spring runtimeException rollback 여부 1. @Transactional, RuntimeException, rollback marking 설명 2. @Transactional 일 때, RuntimeException 이 났는데 try catch 를 이용해서 Exception 을 안냈을 때 어떻게 되는가? 결론부터 얘기하면 Transactional annotation 안에서 RuntimeException 이 일어나면 (예외를 일으키지 않아도), rollback marking 이 찍힌다. 3. source 소스를 설명하면, ServiceA.call() --> ServiceB.call() 를 호출 ServiceA.call 과 ServiceB.call() 은 Transactional 로서 같은 트랜잭션으로 묶일 것이다. serviceB.call() 은 .. 2021. 4. 9. [Spring] ResponseEntity 란? [Spring] ResponseEntity 란? Spring 에서 HttpRequest 에 대해 제공하는 클래스 HttpBody, HttpHeader, HttpStatus 을 담고 있음. getMember 를 호출하면 member 데이터 (JSON) 와 HttpStatus.OK (200) 을 클라이언트에서 받게 됨. @RestController public class MemberController { @GetMapping("/member/{id}") public ResponseEntity getMember(@PathVariable("id") String id) { ... ... return new ResponseEntity(member, HttpStatus.OK); } } Reference https:/.. 2021. 3. 5. 이전 1 ··· 9 10 11 12 13 14 15 ··· 18 다음