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
- mybatis
- 메소드
- Graphic
- 생성자
- 국제화
- 안드로이드
- Java
- JSP
- 기본
- struts2
- OGNL
- Spring
- 배열
- layout
- 에러페이지
- 클래스
- Menu
- 오버로딩
- 메서드
- HTML
- 예외처리
- Android
- 전화걸기
- JavaScript
- 어노테이션
- Eclips
- oracle
- AWT
- 이클립스
- paint
Archives
- Today
- Total
note
Spring @PostConstruct / @PreDestroy 어노테이션과 라이프 사이클 본문
[JSP/Spring] - Spring @Resource 어노테이션
이전 게시물과 연관 있습니다
실행 화면(Main05.java)
init 메소드 동작
close 메소드 동작
기존
ApplicationContext context = new ClassPathXmlApplicationContext(configLocations);
AbstractApplicationContext context = new ClassPathXmlApplicationContext(configLocations);
추가
context.registerShutdownHook();
작업이 끝난후 메모리 정리
라이프 사이클을 만들 수 있지만
많이 사용하는 방법은 아님
applicationContext.xml
HomeController2.java
package madvirus.spring.chap04.homecontrol;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
public class HomeController2 {
private AlarmDevice alarmDevice;
private Viewer viewer;
@Resource(name = "camera1")
private Camera camera1;
@Resource(name = "camera2")
private Camera camera2;
@Resource(name = "camera3")
private Camera camera3;
private Camera camera4;
public void setCamera1(Camera camera1) {
this.camera1 = camera1;
}
public void setCamera2(Camera camera2) {
this.camera2 = camera2;
}
public void setCamera3(Camera camera3) {
this.camera3 = camera3;
}
@Resource(name = "camera4")
public void setCamera4(Camera camera4) {
this.camera4 = camera4;
}
@PostConstruct
public void init(){
System.out.println("init 메소드 동작");
}
@PreDestroy
public void close(){
System.out.println("close 메소드 동작");
}
}
Main05.java
package madvirus.spring.chap04.homecontrol;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main05 {
public static void main(String[] args) {
String[] configLocations = new String[] { "applicationContext.xml" };
AbstractApplicationContext context = new ClassPathXmlApplicationContext(
configLocations);
context.registerShutdownHook();
HomeController2 home = context.getBean("homeController2",HomeController2.class);
}
}
'JSP > Spring' 카테고리의 다른 글
Spring AOP (1) | 2012.03.02 |
---|---|
Spring @Component 어노테이션을 이용한 자동 스캔 (0) | 2012.03.02 |
Spring @Resource 어노테이션 (0) | 2012.03.02 |
Spring @Qualfier 어노테이션 (0) | 2012.02.29 |
Spring @Autowired 어노테이션 (0) | 2012.02.29 |