Notice
Recent Posts
Recent Comments
Tags
- 알고리즘 문제
- 이분탐색
- spring 기초
- 코딩테스트
- 프로그래머스
- 항해99 코테 스터디
- 프로그래머스 레벨1
- TIL
- 백준
- 스프링 기초
- 백준 다이나믹프로그래밍
- 백준 구현
- 백준 DFS와 BFS
- Django 기초
- 항해99
- 다이나믹 프로그래밍
- Spring 초보
- 코테
- dp 알고리즘
- 브루트포스
- 장고 기초
- 스프링 초보
- programmers
- 백준 dp
- BFS
- 코딩테스트 연습
- 프로그래머스 level1
- 99클럽 코테 스터디
- 알고리즘 공부
- 코테 연습
Archives
- Today
- Total
일일구름 IT
[Spring] 스프링 설정 파일 분리 (문자열 배열, import) 본문
스프링 설정 파일 분리
하나의 xml 파일에 너무 많은 코드 내용이 있으면 가독성이나 관리에 좋지 않기 때문에 스프링 설정 파일을 분리할 필요가 있다.
스프링 설정 파일을 분리하는 첫 번째 방법은 하나의 applicationContext.xml 파일을 여러 개의 xml 파일을 만들어 분리하는 것이다. 분리할때는 bean 객체들의 기능에 따라 내용을 나누는 것이 좋다.
1. 문자열 배열
GenericXmlApplicationContext의 매개변수로 여러개의 xml 파일을 넣기 위해서는
다음과 같이 xml 파일들의 위치들을 담은 문자열 배열을 하나 만들어준 뒤, 그 문자열 배열을 GenericXmlApplicationContext의 매개변수로 넣어주면 된다.
String[] appCtxs = {"classpath:appCtx1.xml", "classpath:appCtx2.xml", "classpath:appCtx3.xml"};
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(appCtxs);
2. import
다른 여러개의 xml 파일을 import를 이용해 1개의 xml 파일에서 사용할 수 있다.
다음과 같이 appCtxImport.xml에서 import 태그를 이용해 appCtx2.xml과 appCtx3.xml을 import하면 GenericXmlApplicationContext에 appCtxImport.xml만 매개변수로 주어도 appCtx2.xml과 appCtx3.xml의 bean 객체를 사용할 수 있다.
<import resource="classpath:appCtx2.xml"/>
<import resource="classpath:appCtx3.xml"/>
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("classpath:appCtxImport.xml");
'Spring' 카테고리의 다른 글
[Spring] 생명주기 (Life Cycle) (2) | 2023.11.28 |
---|---|
[Spring] 의존객체 선택 (@Qualifier, @Named) (0) | 2023.11.11 |
[Spring] 의존객체 자동 주입 (@Autowired, @Resource, @Inject) (0) | 2023.11.09 |
[Spring] bean의 범위 (Prototype) (0) | 2023.11.07 |
[Spring] 다양한 의존 객체 주입 (constructor-arg, property) (2) | 2023.10.29 |