일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- Today
- Total
- 싱글톤 컨테이너
- springsecurity
- qualifier
- Autowired 옵션
- 의존관계 주입
- 객체지향
- HandlerMethodArgumentResolver
- 스프링
- RequiredArgsConstructor
- 롬복 Qualifier
- 스프링 Configuration
- Spring interceptor
- 라즈베리파이4
- 스프링 싱글톤
- UsernamePasswordAuthenticationFilter
- DI컨테이너
- autowired
- ComponentScan
- 스프링 컨테이너
- 도커
- docker
- Spring
- 스프링 빈
- DI
- 빈 중복 오류
- 스프링 빈 조회
- 라즈베리파이
- beandefinition
- Servlet Filter
- 생성자 주입
그날그날 공부기록
BeanFactory & ApplicationContext 본문
BeanFactory와 ApplicationContext를 스프링 컨테이너라고 한다.
BeanFactory(Interface)
↑
ApplicationContext(Interface)
↑
AnnotationConfigApplicationContext
다음과 같은 계층으로 이루어져 있다.
- BeanFactory
- 스프링 컨테이너의 최상위 인터페이스
- 스프링 빈을 관리, 조회하는 역할 → getBean() 제공
- ApplicationContext
- BeanFactory를 상속
- 여러 부가기능을 위해 BeanFactory뿐만 아니라 다음과 같은 인터페이스를 상속받고 있다.
스프링 컨테이너는 자바 코드, XML, Groovy 등 다양한 형식의 설정 정보를 받을 수 있도록 유연하게 설계되어 있다.
자바 코드 → AnnotationConfigApplicationContext
XML → GenericXmlApplicationContext
위의 클래스 모두 ApplicationContext를 상속받는다.
요즘은 자바 코드를 많이 이용한다고 하지만 과거에는 XML을 많이 사용했기 때문에 알아두면 좋다고 한다~
xml로 작성한 AppConfig
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="memberService" class="hello.core.member.MemberServiceImpl" >
<constructor-arg name="memberRepository" ref="memberRepository"/>
</bean>
<bean id="memberRepository" class="hello.core.member.MemoryMemberRepository"/>
<bean id="orderService" class="hello.core.order.OrderServiceImpl">
<constructor-arg name="memberRepository" ref="memberRepository"/>
<constructor-arg name="discountPolicy" ref="discountPolicy"/>
</bean>
<bean id="discountPolicy" class="hello.core.discount.FixDiscountPolicy"/>
</beans>
java로 작성한 AppConfig
@Configuration
public class AppConfig {
@Bean
public MemberService memberService(){
return new MemberServiceImpl(memberRepository());
}
@Bean
public MemberRepository memberRepository() {
return new MemoryMemberRepository();
}
@Bean
public OrderService orderService(){
return new OrderServiceImpl(memberRepository(), discountPolicy());
}
@Bean
public DiscountPolicy discountPolicy(){
return new FixDiscountPolicy();
}
}
두 설정 파일을 비교해보면 언어만 다를 뿐 유사한 것을 확인할 수 있었다.
출처
학습 페이지
www.inflearn.com
ApplicationContext (Spring Framework 5.3.22 API)
Expose AutowireCapableBeanFactory functionality for this context. This is not typically used by application code, except for the purpose of initializing bean instances that live outside the application context, applying the Spring bean lifecycle (fully or
docs.spring.io
'Spring 공부' 카테고리의 다른 글
싱글톤 컨테이너 (0) | 2022.07.19 |
---|---|
BeanDefinition (0) | 2022.07.18 |
스프링 빈 조회 (0) | 2022.07.11 |
스프링 컨테이너 생성 과정 (0) | 2022.07.07 |
IoC, DI, 컨테이너 (0) | 2022.07.06 |