Spring 프레임워크 : "IoC와 AOP를 지원하는 경량의 프레임워크"
<IoC, 스프링 컨테이너 생성 / 컨테이너를 구동시키는 코드>
AbstractApplicationContext factory = new GenericXmlApplicationContext("applicationContext.xml");

결합도를 낮추기 위한 방법
개발 패턴 활용하기
- 팩토리 패턴 - 객체 요청 시 해당 객체를 주는 패턴, ex) HandlerMapper
컨테이너 설정
- 컨테이너 - 개발자 대신 객체 관리
- .xml에서 스프링 컨테이너 설정
설정 요소
beans - 루트(최상위) 엘리먼트 (요소, 태그)
< applicationContext.xml >
<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 class="test.IPhone" id="apple"></bean>
<bean class="test.GalaxyPhone" id="samsung"></bean> -- 빈 등록 == useBean과 닮았다
</beans>
<bean을 불러오는 코드 - UseBean과 유사>
Phone phone = (Phone)factory.getBean(bean 이름);
Phone phone = (Phone)factory.getBean(args[0]);
Bean - 자바객체 : POJO
getBean - 객체를 요청 : look up
args[] - Program arguments로 지정 가능
Run Configurations - Program arguments에 지정후 Run


<bean 설정 코드>
<bean class="test.GalaxyPhone" id="samsung" lazy-init="true" init-method="initMethod" scope="singleton"></bean>
- lazy-init="true" - 지연로딩으로 설정 변경 (default = pre-loading - Run과 동시에 생성자 생성)
- init-method="initMethod" - init() 함수에서 초기화
- scope="singleton" / scope="prototype" - prototype으로 설정 시 생성자 중복 생성 가능
POJO (Plain Old Java Object) 란?
오래된 방식의 간단한 자바 오브젝트로
Java EE 등의 중량 프레임워크들을 사용 시
해당 프레임워크에 종속된 "무거운" 객체를 만들게 된 것에 반발해서 사용
이후에 특정 자바 모델이나 기능, 프레임워크 등을 따르지 않은 자바 오브젝트를 지칭
POJO가 다른 분야에서 사용되는 언어
- POPO : Plain Old PHP Object, PHP 언어에서 사용
- POCO : Plain Old CLR Object, 닷넷 프레임워크에서 사용
- PODS : Plain Old Data Structures, C++ 언어에서 오직 C 언어의 특징만 사용하는 경우
- POD : Plain Old Documentation, 펄(Perl) 언어에서 사용
- POTS : Plain Old Telephone Service
2024.10.01
'Spring' 카테고리의 다른 글
| [Spring] 05. 어노테이션 의존성 주입 (1) | 2024.10.04 |
|---|---|
| [Spring] 04. 의존성 주입 (0) | 2024.10.02 |
| [Spring] 02. Spring 프레임워크 구조 (2) | 2024.10.01 |
| [Spring] 01. Spring의 정의 (1) | 2024.10.01 |
| [Spring] 00. Spring 플러그인 설치 (0) | 2024.09.30 |