-
Notifications
You must be signed in to change notification settings - Fork 10
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
[21기_한혜수] spring tutorial 미션 제출합니다. #6
base: hyesuhan
Are you sure you want to change the base?
Conversation
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.
고생하셨습니다!
- 스프링 IoC 컨테이너가 생성 및 관리하는 자바 객체 | ||
- 과거에는 개발자가 `new`연산자로 객체를 생성하고 생명 주기를 관리 | ||
- IoC 기술을 통해 객체 생성과 관리를 스프링이 대신 | ||
- **스프링 컨테이너에서 관리되는 객체** = **Bean** |
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.
정리👍입니다
// given | ||
Long userId = 1L; | ||
|
||
AccountReqDto.AccountSaveReqDto accountSaveReqDto = new AccountReqDto.AccountSaveReqDto(); |
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.
2가지 DTO를 중첩 클래스로 구현하신 것 같은데 이유와 내부 코드가 궁금해요~!!
혹시 컨트롤러 파라미터로 사용하는 DTO와
컨트롤러->서비스로 데이터를 넘길때 사용하는 DTO를 하나의 파일로 묶고 싶은 의도였을까요?
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.
저는 개인적으로 DTO를 만들 때 프로젝트 스타일에 따라서 달라지는 것 같은데요! 위는 제가 사용한 예시인데, 여기에서는 class 단위로 requestDTO를 관리하고 그 안에서 컨트롤러 마다 세부 DTO를 따로 정의해서 한 코드 안에 정리를 했습니다 XD
Long userId = 1L; | ||
|
||
AccountReqDto.AccountSaveReqDto accountSaveReqDto = new AccountReqDto.AccountSaveReqDto(); | ||
accountSaveReqDto.setNumber(1111L); |
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.
DTO를 불변 객체로 관리해야 한다 VS 아니다
중 후자이신가요?? 저도 후자쪽이지만 그 이유가 궁금합니다
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.
저는 DTO를 프로젝트 마다 다르게 설정하는데, 이 부분에서는 test 코드여서 Dummy 데이터를 넣었다! 라는 의미로 저렇게 setter을 사용했어요!
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.
고생하셨어용~~
src/test/java/com/ceos21/spring_boot/controller/HelloControllerTest.java
Show resolved
Hide resolved
### 2. DI (Dependency Injection) | ||
|
||
- IoC의 구체적인 구현 방식으로, 객체 간의 의존성을 외부에서 주입 받는 기술 | ||
- DI를 사용하면, 의존 객체를 코드 내에서 직접 생성하는 대신, 설정을 통해 외부에서 주입받게 된다. | ||
- @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.
수동 주입 @configuration -> @bean에 대해서도 찾아보면 좋을 것 같아요~!
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.
감사합니다!!! 공부해서 정리 해 볼게요 :)
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.
수동 주입의 경우 @Configuration-@Bean 을 사용하고 자동 주입은 @Component-@Autowired 를 사용한다고 하네요.
기본적으로 자동 주입이 일반적인데, (@controller, @service 와 같은 @component 어노테이션이 비즈니스 로직적으로 이해하기 쉬워요) 다만 기술적인 문제나 공통 관심사를 처리할 때는 수동 빈으로 등록해서 설정 정보가 명확히 드러나는 경우가 더 좋다고 하네요!
### 3. 라이프 사이클 | ||
|
||
- 스프링 IoC 컨테이너 생성 | ||
- 스프링 Bean 생성 | ||
- 의존 관계 주입 | ||
- 초기화 콜백 메소드 호출 (빈의 초기화 작업) | ||
- 로직 수행 및 빈 사용 | ||
- 소멸 전 콜백 메소드 호출 | ||
- 스프링 종료 | ||
|
||
## [스프링 어노테이션을 심층 분석해요] | ||
|
||
### 1. 어노테이션이란? | ||
|
||
- 자바 소스 코드에 추가하는 메타 데이터 | ||
- 실제 실행에는 영향을 주지 않으나 코드의 동작 방식을 설정하거나 특정 동작을 수행하게 만듦 | ||
|
||
### 2. 빈 등록 시 일어나는 과정 분석 | ||
|
||
- Component Scan을 통해 어노테이션이 붙은 클래스를 탐색 | ||
- 빈 정보를 등록 | ||
- 이를 바탕으로 빈 객체를 생성하고, 생성된 빈 사이의 의존성 주입 | ||
- 빈 객체를 IoC 컨테이너에서 관리 | ||
|
||
### 3. @ComponentScan | ||
|
||
- 위 어노테이션을 통해 class path를 탐색하여 자동으로 빈 등록 | ||
- 스프링은 Application 실행 시 @ComponentScan을 기반으로 지정된 패키지 내에서 어노테이션이 부착된 클래스를 탐색 (명시하지 않으면 @ComponentScan을 선언한 클래스의 패키지가 기준) |
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.
👌🏻 이해가 잘되어요
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.
👍 리뷰 감사합니다!
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.
1주차 과제 넘 고생하셨습니다 !!!
spring: | ||
datasource: | ||
url: jdbc:h2:tcp://localhost/~/ceos21 | ||
username: sa | ||
password: 1234 | ||
driver-class-name: org.h2.Driver |
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.
환경변수 처리해서 gitignore 사용하면 좋을 것 같아요!
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.
그냥 복사해서 .gitignore을 안 해놨네요! 다음 과제부터는 ignore 해 놓겠습니다 XD
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.
단위테스트랑 통합테스트를 예시코드와 함께 자세히 써주셔서 좋았어요! 실제로 다른 프로젝트를 하면서 썼던 테스트코드같은데 테스트 코드 작성하는 습관 멋집니당....
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.
저거는 그냥 공부하면서 쓴 것 뿐... 저만 그런지는 모르겠는데 프로젝트에서 테스트를 하려는 습관이 어렵더라고요 . . .(사실 impl 도 하기 시간이 빡세서 ㅠ)
import jakarta.persistence.Id; | ||
import lombok.Data; | ||
|
||
@Data |
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.
@DaTa 어노테이션이 자동으로 생성하는 메서드에 뭐뭐가 있는지 알아봐도 좋을 것 같습니다! 평소에 이 어노테이션을 쓸 일도 볼 일도 별로 없으니.. 이번 기회에 ..!
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.
@DaTa 는 롬복에서 지원하는 !!(@Setter, @Getter 과 같은) 어노테이션인데, 일반적으로 DTO 같은 모델에서 많이 사용합니다. 찾아보니 @DaTa 어노테이션이 @Getter, @Setter, @tostring 등을 합쳐 놓은 거라네요!! 저... 처음 알았어요.. 한번쯤은 @DaTa와 @Getter 을 같이 쓴 적도 있는 것 같고, @DaTa 만 사용할 때는 GPT 이용해서 만든거여서 그냥 데이터여서 그렇구나~ 하고 넘어갔는데 이런 이유가 있었네요!!! 평소에 @Setter을 안 사용하려고 해서 @DaTa가 없는 거였어요!!!! 기본적인데 뭔가 까먹고 당연하게 사용하고 있었네용..
No description provided.