Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User JPA 적용, BindException 처리 #26

Merged
merged 6 commits into from
Feb 21, 2023

Conversation

yeonkyungJoo
Copy link
Collaborator

  1. JPA 적용
  2. ApiResult 적용 및 Controller 테스트 작성
  3. Validation 체크 및 ControllerExceptionAdvice 생성

class UserServiceTest {

UserService userService;
@Autowired
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

junit5부터는 생성자 주입방식도 활용할 수 있다고 알고 있는데
@Testconstructor(autowireMode = TestConstructor.AutowireMode.ALL)에 대해서도
같이 공부하면 좋을 거 같습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 감사합니다.

@Autowired
UserRepository userRepository;

@PostConstruct
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이걸 보니까 저번에 @f-lab-lyan 멘토님이 권장하지 않는 방법이라고 적어주셨는데 같이 공부해보면 좋을 거 같습니다!

  • 장점
  1. bean이 초기화됨과 동시에 의존성을 확인할 수 있다는 장점
  2. bean lifeCycle에서 오직 한 번만 수행된다는 것이 보장된다는 장점
  • 단점
  1. @transactional과 관련된 단점
  • userService.save 호출(@transactional 선언) -> userService -> userRepository = 동일한 트랜잭션 -> context init이 이루어진 상태 -> 정상 작동
  • userRepository.save 호출(@transactional이 선언되어 있지 않은 경우) -> userRepository = @transactional이 적용되었다는 보장 X -> 정상 작동 X

다른 의견 있으시면 답변 부탁드릴게요! :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CHANEE-personal 트랜잭션 관련된 단점이 이해가 잘 안 가요!
일단 저는 그 코드에서는 PostConstruct를 사용하지 않는 것이 맞다고 판단했었는데, 이 코드에서도 좋은 방법이 아닌지는 판단이 잘 서지 않아서요! 다시 확인해보겠습니다!!

@CHANEE-personal CHANEE-personal merged commit 7dd8d23 into f-lab-edu:main Feb 21, 2023
CHANEE-personal pushed a commit to CHANEE-personal/bbaemin that referenced this pull request Feb 22, 2023
* User - JPA 적용

* User - ApiResult 적용 및 Controller 테스트 작성

(cherry picked from commit 4239842)

* Validation 체크 및 ControllerExceptionAdvice 생성

(cherry picked from commit e38b6f6)

* updateUserInfo - Patch로 변경

* Validation 체크 예외를 MethodArgumentNotValidException으로 변경

* ApiResult - ResultCode.CREATED 추가
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants