728x90
반응형
다양한 설정 형식 지원 - 자바 코드, XML
XML 설정 사용
GenericXmlApplicationContext를 사용하면서 xml 설정 파일을 넘기면 된다.
public class XmlAppContext {
@Test
void xmlAppContext() {
ApplicationContext ac = new GenericXmlApplicationContext("appConfig.xml");
MemberService memberService = ac.getBean("memberService", MemberService.class);
assertThat(memberService).isInstanceOf(MemberService.class);
}
}
위치 : src/main/resources/appConfig.xml
<?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.RateDiscountPolicy"/>
</beans>
스프링 공식 레퍼런스 문서
https://spring.io/projects/spring-framework
인프런 강의 "스프링 핵심 원리 - 기본편"을 정리한 것 입니다.
스프링 핵심 원리 - 기본편 - 인프런 | 강의
스프링 입문자가 예제를 만들어가면서 스프링의 핵심 원리를 이해하고, 스프링 기본기를 확실히 다질 수 있습니다., - 강의 소개 | 인프런...
www.inflearn.com
728x90
반응형
'스프링 Spring > 스프링 핵심 원리 - 기본편' 카테고리의 다른 글
[싱글톤 컨테이너] 웹 애플리케이션과 싱글톤 (0) | 2022.02.05 |
---|---|
[스프링 컨테이너와 스프링 빈] 스프링 빈 설정 메타 정보 - BeanDefinition (0) | 2022.02.05 |
[스프링 컨테이너와 스프링 빈] BeanFactory와 ApplicationContext (0) | 2022.02.03 |
[스프링 컨테이너와 스프링 빈] 스프링 빈 조회 - 상속 관계 (0) | 2022.02.03 |
[스프링 컨테이너와 스프링 빈] 스프링 빈 조회 - 동일한 타입이 둘 이상 (0) | 2022.02.02 |
댓글