Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 열혈 tcp/ip 프로그래밍
- 2475번
- FIFO paging
- Window-Via-c/c++
- 스프링 핵심 원리
- n타일링2
- inflearn
- 열혈 TCP/IP 소켓 프로그래밍
- Operating System
- 운영체제
- Four Squares
- 에러핸들링
- Operating System.
- 윤성우 저자
- 우아한 테크 세미나
- TCP/IP
- Spring
- OS
- redis
- 우아한레디스
- BOJ
- 제프리리처
- 김영한
- 이펙티브코틀린
- HTTP
- C#
- 10026번
- 스프링 입문
- C++
- 토마토
Archives
- Today
- Total
나의 브을로오그으
#4-4. [스프링 핵심 원리-기본편] - 다양한 설정 형식 지원 본문
다양한 설정 형식 - JAVA, XML

- 애노테이션 기반 자바 코드 설정 사용
* 가장 많이 사용하는 방식
* new AnnotationConfigApplicationContext(AppConfig.class);
* AnnotationConfigApplicationContext 클래스를 사용하면서 자바 코드로된 설정 정보를 넘기면 된다.
- XML 설정 사용
- 최근에는 스프링 부트를 많이 사용하면서 XML기반의 설정은 잘 사용하지 않는다. 아직 많은 레거시 프로젝트 들이 XML로 되어 있고, 또 XML을 사용하면 컴파일 없이 빈 설정 정보를 변경할 수 있는 장점도 있으므로 한번쯤 배워두는 것도 좋다.
- GenericXmlApplicationContext를 사용하면서 xml 설정 파일을 넘기면 된다.
[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>
[XmlAppContextTest]
package hello.core.xml;
import hello.core.member.MemberService;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.context.support.GenericXmlApplicationContext;
public class XmlAppContextTest {
@Test
void xmlAppContext() {
GenericXmlApplicationContext ac = new GenericXmlApplicationContext("appConfig.xml");
MemberService memberService = ac.getBean("memberService", MemberService.class);
Assertions.assertThat(memberService).isInstanceOf(MemberService.class);
}
}
- xml 기반의 appConfig.xml 스프링 설정 정보와 자바 코드로 된 AppConfig.java 설정 정보를 비교해보면 거의 비슷하다는 것을 알 수 있다.
- xml 기반으로 설정하는 것은 최근에 잘 사용하지 않으므로 참고로만 알고있자.
https://spring.io/projects/spring-framework
Spring Framework
spring.io
'Spring' 카테고리의 다른 글
#5-1. [스프링 핵심 원리-기본편] - 싱글턴 패턴 (0) | 2022.07.21 |
---|---|
#4-5. [스프링 핵심 원리-기본편] - 스프링 빈 설정 메타 정보 (0) | 2022.07.20 |
#4-3. [스프링 핵심 원리-기본편] - BeanFactory와 ApplicationContext (0) | 2022.07.19 |
#4-2. [스프링 핵심 원리-기본편] - 스프링 빈 조회 (0) | 2022.07.19 |
#4-1. [스프링 핵심 원리-기본편] - 스프링 컨테이너 (0) | 2022.07.19 |