-
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 미션 제출합니다. #13
base: WithFortuna
Are you sure you want to change the base?
Conversation
- Spring : SOLID, POJO, AOP, PSA, 스프링 빈 - 어노테이션 - 테스트 코드
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주차 과제 하시느라 정말 수고 많으셨습니다. 앞으로도 화이팅입니다!!
**Q. @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.
어떤 추가 설정이 가능한가요?
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.
테스트데이터를 초기화하거나 간단한 캐싱작업에도 활용할 수 있다고 합니다
조금 더 공부해봐야겠네요.!
`AnnotationConfigApplicationContext` (자식) | ||
→ `GenericApplicationContext` (부모) | ||
→ *BeanFactory 인터페이스* | ||
→ *BeanDefinitionRegistry 인터페이스* | ||
|
||
// 코드 | ||
public class GenericApplicationContext implements BeanFactory, BeanDefinitionRegistry { | ||
private DefaultListableBeanFactory beanFactory; | ||
|
||
public Object getBean() { | ||
beanFactory.getBean(); // 위임 | ||
} | ||
} |
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.
BeanFactory와 BeanDefinitionRegistry
의 관계를 잘 정리해주셨는데, Spring에서는 일반적으로 ApplicationContext
를 더 많이 사용한다고 합니다. BeanFactory
와 ApplicationContext
의 차이는 무엇일까요?
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.
저도 궁금해서 찾아봤었는데
- BeanFactory : 빈 생성, 관리 기능 //스프링 빈 Lazy 초기화
- ApplicationContext: (빈 생성,관리기능) + AOP + 국제화 //스프링 빈Eager 초기화
약간은 추상적지만.. 빈팩토리가 빈 관련된 기능만 제공한다면 앱컨텍스트는 거기에 더해서 상위기능들을 같이 제공하더라고요
public class GenericApplicationContext implements BeanFactory, BeanDefinitionRegistry { | ||
private DefaultListableBeanFactory beanFactory; | ||
|
||
public Object getBean() { | ||
beanFactory.getBean(); // 위임 | ||
} | ||
} |
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.
코드 예시 들어주신거 너무 좋은데요?
GenericApplicationContext
가 직접 getBean()
을 호출하지 않고, 내부적으로 DefaultListableBeanFactory
에 위임하는 이유는 무엇인가요?
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.
오 질문이 날카롭습니다..
GenericApplicationContext
가 직접 getBean()
함수를 구현하지 않고 별도의 구현체인 DefaultListableBeanFactory
를 멤버변수로 두고 사용하는 방식이 저도 낯설더라고요.
일단 몇가지 이유를 찾아봤는데
- 결합도 낮추기
:ApplicationContext(AC)
는 여러 상위 기능을 한꺼번에 제공해야합니다. 따라서 직접 구현하거나 상속하는 방식을 택한다면 AC가 너무 많은 책임을 지게 됩니다. - 확장성 높이기
: 새로운 빈팩토리가 필요하면 멤버변수를 교체만 하면 됩니다. 또 국제화와 같은 상위기능을 더하고 싶을 때에도 멤버로 추가하거나 빈으로 등록만 하면 되므로 확장하기가 쉽습니다!
보통 조합과 위임이라고 표현하는 것 같습니다
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. 스프링 빈 | ||
|
||
- **의미:** 스프링 컨테이너에서 생성과 소멸을 관리하는 **싱글톤 객체** | ||
싱글톤 객체: 동일한 인스턴스로 같은 메모리 점유 |
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.
싱글톤 객체의 설명을 보고 static 클래스와 spring bean의 차이점이 궁금해서 찾아보았는데 잘 설명되어있는 것 같아 첨부합니다~
싱글톤 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.
오.. 리뷰 보고나니까 저도 궁금해져서 링크 보고 왔습니다
싱글톤 객체 구현 방식이 꽤 다양하네요. 좋은 자료 감사합니다!
|
||
// 코드 | ||
@Target(ElementType.???) // TYPE, METHOD, FIELD | ||
@Retention(RetentionPolicy.???) // RUNTIME, CLASS, SOURCE |
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.
저는 해당 부분을 조사할 때 @Retention
어노테이션의 기능이 헷갈렸어서, 혹시나 참고하시라고 제가 참고했던 글 남깁니다. 블로그의 댓글에 어떤 분이 잘 설명해주신 것 같아요.
retention어노테이션
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.
RetentionPolicy.CLASS는 저도 이게 굳이 왜 필요한지 이해가 잘 안갔었는데 덕분에 배워갑니다 👍
1주차 README