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 | 31 |
Tags
- 메소드
- Menu
- 어노테이션
- 클래스
- 오버로딩
- Java
- 메서드
- layout
- oracle
- Android
- Spring
- 배열
- 생성자
- 이클립스
- 기본
- HTML
- 에러페이지
- 예외처리
- AWT
- mybatis
- 전화걸기
- Graphic
- Eclips
- struts2
- 국제화
- OGNL
- JavaScript
- paint
- JSP
- 안드로이드
Archives
- Today
- Total
note
Spring 프로퍼티 이름을 이용한 의존 관계 자동 설정 본문
applicationContext02.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 프로퍼티 이름을 이용한 의존 관계 자동 설정 -->
<bean name="writeArticleService" class="madvirus.spring.chap02.WriteArticleServiceImpl" autowire="byName" />
<bean name="articleDao" class="madvirus.spring.chap02.MySQLArticleDao" />
</beans>
Main05
package madvirus.spring.chap02;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main05 {
public static void main(String[] args) {
String[] configLocations = new String[] { "applicationContext02.xml" };
ApplicationContext context = new ClassPathXmlApplicationContext(
configLocations);
// 프로퍼티 이름을 이용한 의존 관계 자동 설정
WriteArticleService articleService = (WriteArticleService) context
.getBean("writeArticleService");
articleService.write(new Article());
}
}
MySQLArticleDao
package madvirus.spring.chap02;
public class MySQLArticleDao implements ArticleDao{
@Override
public void insert(Article article) {
System.out.println("MySQLArticleDao.insert()실행");
}
}
WriteArticleService
package madvirus.spring.chap02;
public interface WriteArticleService {
void write(Article article);
}
Article
package madvirus.spring.chap02;
public class Article {
}
'JSP > Spring' 카테고리의 다른 글
| Spring 국제화 (0) | 2012.02.29 |
|---|---|
| Spring 프로퍼티 타입을 이용한 의존 관계 자동 설정 (0) | 2012.02.29 |
| Spring Di 심화 학습 (0) | 2012.02.29 |
| Spring Di(Dipendency Injection) (0) | 2012.02.28 |
| Spring 설치 & 셋팅(응용 프로그램) (0) | 2012.02.28 |