Skip to content

[24기_구동현] spring tutorial 미션 제출합니다. - #6

Open
9dongs wants to merge 3 commits into
CEOS-Developers:9dongsfrom
9dongs:9dongs
Open

[24기_구동현] spring tutorial 미션 제출합니다.#6
9dongs wants to merge 3 commits into
CEOS-Developers:9dongsfrom
9dongs:9dongs

Conversation

@9dongs

@9dongs 9dongs commented Sep 9, 2026

Copy link
Copy Markdown

CEOS 1주차 미션 제출입니다.

@Seungwon326 Seungwon326 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

아주 꼼꼼하게 정리해주셨네요👍
덕분에 저도 다시 한 번 공부 할 수 있었습니다!
고생하셨습니다!!

Comment on lines +3 to +5
url: jdbc:mysql://localhost:3306/${database}?allowPublicKeyRetrieval=true&useSSL=false&characterEncoding=UTF-8
username: root
password: ${password}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

db 이름이나 비밀번호를 환경변수로 잘 처리 해주셨네요!!
앞으로도 민감한 정보들은 신경써서 관리해주세요!!👍

Comment thread README.md
Comment on lines +302 to +304
### 같은 인터페이스의 구현체가 여러 개라면??!?

Spring은 먼저 타입을 기준으로 주입할 Bean을 찾는다. 같은 타입의 구현체가 여러 개면 `@Primary`나 `@Qualifier`로 하나를 선택한다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@Primary@Qualifier 외에도 필드 명이나 파라미터 명과 빈 이름을 매칭시키는 방법도 있습니다!

이 방법은 주입받는 변수명이나 생성자 파라미터 이름을 구현체 클래스 이름(첫 글자 소문자)과 일치시키면 스프링이 알아서 그 이름을 가진 빈을 찾아주는 방식입니다

해당 내용에 대해서도 공부해보면 좋을거같아요!

Comment thread README.md
Comment on lines +204 to +223
### 의존관계 주입 방법

| 방식 | 특징 |
| --- | --- |
| 생성자 주입 | 필수 의존성을 받고 `final`을 사용할 수 있어 주로 권장한다. |
| 수정자 주입 | 나중에 바뀔 수 있거나 선택적인 의존성에 사용한다. |
| 필드 주입 | 코드는 짧지만 의존성이 잘 드러나지 않고 단위 테스트가 불편하다. |

```java
@Service
class OrderService {
private final PaymentService paymentService;

OrderService(PaymentService paymentService) {
this.paymentService = paymentService;
}
}
```

생성자가 하나라면 `@Autowired`를 생략할 수 있다. Lombok의 `@RequiredArgsConstructor`를 사용하면 `final` 필드를 받는 생성자도 자동으로 만들 수 있다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

의존성 주입 방식과 각각의 장단점을 작성해주셔서 차이를 쉽게 비교하며 읽었습니다. 감사합니다~

Comment thread README.md
`HandlerMapping`은 애플리케이션 시작 과정에서 `@GetMapping`, `@RequestMapping` 등이 붙은 Controller 메서드를 미리 연결해 둔다. 요청이 오면 이 정보를 이용해 처리할 Controller Bean을 찾는다.

---
### `doDispatch()` 흐름

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

doDispatch() 단계를 차례대로 정리해주셔서 요청이 Controller까지 가는 과정이 이해하기 쉬웠습니다 ! 특히 HandlerMapping이 Controller를 찾는 단계와 HandlerAdapter가 실제로 호출하는 단계를 분리해서 설명해주신 게 왜 Spring이 이 둘을 나눴는지 이해하는 데 도움이 많이 됐습니다 감사합니당 😊

Comment thread README.md

Spring은 prototype Bean의 생성, 의존관계 주입, 초기화까지만 담당한다. 이후의 정리 작업은 사용하는 쪽에서 처리해야 한다.

또한 singleton Bean에 prototype Bean을 주입하면 singleton을 만들 때 한 번만 주입된다. 메서드를 호출할 때마다 새 객체가 필요하다면 `ObjectProvider`처럼 그때 Bean을 조회하는 방법을 사용할 수 있다.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

prototype Bean이 singleton에 한 번만 주입되는 문제, ObjectProvider로 해결 방법까지 정리해주셔서 좋았습니다!! 덕분에 개념을 더 깊게 이해할 수 있었어요 감사합니다 😊

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.

4 participants