* Spring 설치 (플러그인 설치) *
help -> Eclipse Marketplace -> Spring 검색 -> Spring tools 3 3.9.14 install
install new software -> add -> name: STS Location: https://dist.springsource.com/snapshot/TOOLS/nightly/e4.18 add -> select all -> next
이클립스를 재시작하라는 안내문구 -> 재시작
* 설치확인 *
1. window - preference 메뉴에 Spring 있으면 설치완료
2. explorer 우클릭 - new 메뉴에Spring legacy Project 있는지 확인
=> 없을경우 Marketplace에서 Spring Tools 3 Add-On for Spring Tools 설치
* 적용 *
SpringLagacyProject - next - ProjectName입력 - Spring MVCproject선택후 -next - level설정 (보통 3단계 ex> com.kim.app) - 기본적으로 controller를 제공
cmd창에서 java -version 명령어로 자바 버전 확인 -
프로젝트 우클릭 properties - ProjectFacets 에서 자바 버전 설정, Runtimes들어가서 서버 연결 하고 Apply - Apply and Close
src/main/resources 에는 log4.xml만 있도록
webapp - WEBINF에 web.xml있는지확인
Spring, View 제거
web.xml
wep-app 루트 엘리먼트를 제외한 나머지 요소 삭제
pom.xml
<org.springframework-version>4.2.4.RELEASE</org.springframework-version>
로 변경 후 - Project 우클릭 - maven - updateProject -
완료후 Libraries에서 Maven Dependency - spring~4.2.4로 변경되었는지 확인
스프링
IoC 컨테이너
-> 객체를 어떻게 관리할지에 대한 설정파일(.xml)이 필요
-> Servlet컨테이너도 IoC컨테이너
1. 서블릿 클래스 -- 인스턴스화 new --> 객체화
2. web.xml
* 사용법 *
src/main/resources - 우클릭 - new - other - Spring Bean Configuration File : applicationContext.xml - next - finish
-> 스프링 컨테이너가 관리할 클래스를 등록 (매핑) - <bean></bean> 사용
applicationContext.xml - 하단 탭 Namespaces - 사용할때마다 추가
* 사용*
test.Test 생성 - syso("기본생성자 호출됨")
<bean class="test.Test" id = "test" /> <!-- 클래스에 파란색 S 가 추가되는데 이건 스프링 컨테이너에 관리되고있다는 뜻! -->
<!-- Test test = new Test(); 와 같다 -->
test.Client
AbstractApplicationContext factory = new GenericXmlApplicationContext("applicationContext.xml");
1. 스프링 컨테이너 동작
2. 객체를 요청(Look up)하면, 해당 객체를 준다.
- 현재 bean에 등록된 모든 클래스에 대한 객체를 미리 만들어 놓는다!
- pre-loading 즉시 로딩!
- 즉시 로딩 사용 안함 설정가능 (lazy loading : 지연 로딩)
Test t = (Test)factory.getBean("test");
t.print();
3. 스프링 컨테이너 종료
factory.close();
'Spring' 카테고리의 다른 글
| 생성자 인젝션 (0) | 2021.12.05 |
|---|---|
| applicationContext.xml 의 역할 (0) | 2021.12.05 |
| SpringFramework BeanFactory (0) | 2021.09.27 |
