-
Notifications
You must be signed in to change notification settings - Fork 3
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
User JPA 적용, BindException 처리 #26
Conversation
yeonkyungJoo
commented
Feb 18, 2023
- JPA 적용
- ApiResult 적용 및 Controller 테스트 작성
- Validation 체크 및 ControllerExceptionAdvice 생성
e38b6f6
to
66be67a
Compare
bbaemin-api/src/main/java/org/bbaemin/user/controller/UserController.java
Outdated
Show resolved
Hide resolved
bbaemin-api/src/main/java/org/bbaemin/config/advice/ControllerExceptionAdvice.java
Outdated
Show resolved
Hide resolved
bbaemin-api/src/main/java/org/bbaemin/config/advice/ControllerExceptionAdvice.java
Show resolved
Hide resolved
bbaemin-api/src/main/java/org/bbaemin/user/controller/UserController.java
Outdated
Show resolved
Hide resolved
class UserServiceTest { | ||
|
||
UserService userService; | ||
@Autowired |
There was a problem hiding this comment.
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)에 대해서도
같이 공부하면 좋을 거 같습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 감사합니다.
bbaemin-api/src/main/java/org/bbaemin/user/controller/UserController.java
Show resolved
Hide resolved
@Autowired | ||
UserRepository userRepository; | ||
|
||
@PostConstruct |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이걸 보니까 저번에 @f-lab-lyan 멘토님이 권장하지 않는 방법이라고 적어주셨는데 같이 공부해보면 좋을 거 같습니다!
- 장점
- bean이 초기화됨과 동시에 의존성을 확인할 수 있다는 장점
- bean lifeCycle에서 오직 한 번만 수행된다는 것이 보장된다는 장점
- 단점
- @transactional과 관련된 단점
- userService.save 호출(@transactional 선언) -> userService -> userRepository = 동일한 트랜잭션 -> context init이 이루어진 상태 -> 정상 작동
- userRepository.save 호출(@transactional이 선언되어 있지 않은 경우) -> userRepository = @transactional이 적용되었다는 보장 X -> 정상 작동 X
다른 의견 있으시면 답변 부탁드릴게요! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CHANEE-personal 트랜잭션 관련된 단점이 이해가 잘 안 가요!
일단 저는 그 코드에서는 PostConstruct를 사용하지 않는 것이 맞다고 판단했었는데, 이 코드에서도 좋은 방법이 아닌지는 판단이 잘 서지 않아서요! 다시 확인해보겠습니다!!