Skip to content

Commit

Permalink
hotfix: Event가 Transaction commt 후 핸들하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ori0o0p committed Aug 31, 2024
1 parent 9457464 commit 6565b4f
Showing 1 changed file with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@
import com.repo.whopper.common.exception.student.StudentNotFoundException;
import com.repo.whopper.domain.student.StudentRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@Slf4j(topic = "StudentMajorUpdateEventHandler-")
@RequiredArgsConstructor
public class StudentMajorUpdateEventHandler {
private final StudentRepository studentRepository;

@Async
@EventListener(StudentMajorUpdateEvent.class)
@Transactional
@TransactionalEventListener(StudentMajorUpdateEvent.class)
public void handle(StudentMajorUpdateEvent event) {
log.info("StudentMajorUpdateEvent 실행됌!!");

final var student = studentRepository.findById(event.studentId())
.orElseThrow(() -> StudentNotFoundException.EXCEPTION);
final var newStudent = student.updateMajor(event.majorId(), event.majorName());
Expand Down

0 comments on commit 6565b4f

Please sign in to comment.