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

[21기_최근호] spring tutorial 미션 제출합니다. #13

Open
wants to merge 4 commits into
base: WithFortuna
Choose a base branch
from

Conversation

WithFortuna
Copy link

1주차 README

Copy link

@seoahS01 seoahS01 left a comment

Choose a reason for hiding this comment

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

1주차 과제 하시느라 정말 수고 많으셨습니다. 앞으로도 화이팅입니다!!

**Q. @PostConstruct가 적용되는 시점은?**
⇒ 초기화 단계의 **마지막**에 호출된다.
객체가 생성(메모리 힙에 할당), 의존성이 주입되고 필요한 설정들도 끝난 초기화의 마지막 단계.
(이때 개발자가 원하는 추가 설정이 가능)

Choose a reason for hiding this comment

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

어떤 추가 설정이 가능한가요?

Copy link
Author

Choose a reason for hiding this comment

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

테스트데이터를 초기화하거나 간단한 캐싱작업에도 활용할 수 있다고 합니다
조금 더 공부해봐야겠네요.!

Comment on lines +136 to +148
`AnnotationConfigApplicationContext` (자식)
→ `GenericApplicationContext` (부모)
→ *BeanFactory 인터페이스*
→ *BeanDefinitionRegistry 인터페이스*

// 코드
public class GenericApplicationContext implements BeanFactory, BeanDefinitionRegistry {
private DefaultListableBeanFactory beanFactory;

public Object getBean() {
beanFactory.getBean(); // 위임
}
}

Choose a reason for hiding this comment

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

BeanFactory와 BeanDefinitionRegistry의 관계를 잘 정리해주셨는데, Spring에서는 일반적으로 ApplicationContext를 더 많이 사용한다고 합니다. BeanFactoryApplicationContext의 차이는 무엇일까요?

Copy link
Author

@WithFortuna WithFortuna Mar 17, 2025

Choose a reason for hiding this comment

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

저도 궁금해서 찾아봤었는데

  • BeanFactory : 빈 생성, 관리 기능 //스프링 빈 Lazy 초기화
  • ApplicationContext: (빈 생성,관리기능) + AOP + 국제화 //스프링 빈Eager 초기화
    약간은 추상적지만.. 빈팩토리가 빈 관련된 기능만 제공한다면 앱컨텍스트는 거기에 더해서 상위기능들을 같이 제공하더라고요

Comment on lines +142 to +148
public class GenericApplicationContext implements BeanFactory, BeanDefinitionRegistry {
private DefaultListableBeanFactory beanFactory;

public Object getBean() {
beanFactory.getBean(); // 위임
}
}

Choose a reason for hiding this comment

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

코드 예시 들어주신거 너무 좋은데요?
GenericApplicationContext가 직접 getBean()을 호출하지 않고, 내부적으로 DefaultListableBeanFactory에 위임하는 이유는 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

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

오 질문이 날카롭습니다..
GenericApplicationContext가 직접 getBean()함수를 구현하지 않고 별도의 구현체인 DefaultListableBeanFactory를 멤버변수로 두고 사용하는 방식이 저도 낯설더라고요.
일단 몇가지 이유를 찾아봤는데

  1. 결합도 낮추기
    : ApplicationContext(AC) 는 여러 상위 기능을 한꺼번에 제공해야합니다. 따라서 직접 구현하거나 상속하는 방식을 택한다면 AC가 너무 많은 책임을 지게 됩니다.
  2. 확장성 높이기
    : 새로운 빈팩토리가 필요하면 멤버변수를 교체만 하면 됩니다. 또 국제화와 같은 상위기능을 더하고 싶을 때에도 멤버로 추가하거나 빈으로 등록만 하면 되므로 확장하기가 쉽습니다!

보통 조합과 위임이라고 표현하는 것 같습니다

Copy link

Choose a reason for hiding this comment

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

오 이 헬스 컨트롤러는 추가로 넣으신건가요 ?!

Copy link
Author

Choose a reason for hiding this comment

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

서버 체크용으로 자주 써서 넣어봤습니다!

Copy link

@challonsy challonsy left a comment

Choose a reason for hiding this comment

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

설명 잘 읽었습니다!

## 1. 스프링 빈

- **의미:** 스프링 컨테이너에서 생성과 소멸을 관리하는 **싱글톤 객체**
싱글톤 객체: 동일한 인스턴스로 같은 메모리 점유

Choose a reason for hiding this comment

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

싱글톤 객체의 설명을 보고 static 클래스와 spring bean의 차이점이 궁금해서 찾아보았는데 잘 설명되어있는 것 같아 첨부합니다~
싱글톤 vs 정적클래스

Copy link
Author

Choose a reason for hiding this comment

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

오.. 리뷰 보고나니까 저도 궁금해져서 링크 보고 왔습니다
싱글톤 객체 구현 방식이 꽤 다양하네요. 좋은 자료 감사합니다!


// 코드
@Target(ElementType.???) // TYPE, METHOD, FIELD
@Retention(RetentionPolicy.???) // RUNTIME, CLASS, SOURCE

Choose a reason for hiding this comment

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

저는 해당 부분을 조사할 때 @Retention 어노테이션의 기능이 헷갈렸어서, 혹시나 참고하시라고 제가 참고했던 글 남깁니다. 블로그의 댓글에 어떤 분이 잘 설명해주신 것 같아요.
retention어노테이션

Copy link
Author

Choose a reason for hiding this comment

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

RetentionPolicy.CLASS는 저도 이게 굳이 왜 필요한지 이해가 잘 안갔었는데 덕분에 배워갑니다 👍

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

4 participants