본문 바로가기

spring36

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.
Spring Async 처리 (@Async) Spring Async 처리 sync 란 호출 후 응답을 기다리는거고, async 는 호출 후 응답을 기다리지 않는 것입니다. 이러한 특징 떄문에 Async 의 경우 오래 걸리는 작업을 호출한 후, 응답을 즉시 반환할 수 있습니다. Spring 에서 @Async annotation 을 설정해두면 호출하는 스레드는 즉시 리턴하고, Spring 스레드 풀에서 Thread 처리를 수행합니다. @Async 라고 선언된 annotation 이 spring aop 에 의해서 감지되서 수행 됩니다. spring Async 샘플 source AsyncConfig AsyncConfig 를 통해 Spring 에서 Async 설정을 어떻게 할지 알려줍니다. AsyncConfig 에 @EnableAsync 를 선언함으로써 관.. 2021. 2. 21.
@Component, @Repository, @Service, @Controller 설명 및 차이점 @Component, @Repository, @Service, @Controller 설명 및 차이점 @Component 는 스프링에서 관리하는 컴포넌트라는 것이다. @Repository, @Service, @Controller 는 컴포넌트의 하위 개념이다. 전부 Spring 에서 관리하는 컴포넌트들이며, @Repository 는 영속성을 담당하겠다는 것을 명시하는 컴포넌트 @Service 는 비즈니스 로직을 담당하겠다는 컴포넌트. @Controller 는 Handler Mapping 을 위해 사용된다고 해야하나? DispatchServlet 에서 url 이 들어오면 해당 controller 의 RequestMapping 을 통해 맵핑시켜 줌. 이렇게 세분화하는 것이 유지 보수성이나 의미를 전달하기에 더 .. 2020. 12. 25.