[Spring] @Autowired의 Before/After
Posted at 2009/04/29 15:35// Posted in 나만의 작업/Spring
알고있는 내용이기에~ 그냥 가볍게 Before 와 After code
Before - @Autowired annotation이 없었을 때
applicationContext.xml에서 설정
<bean id="empDao" class="EmpDao" /> <bean id="empManager" class="EmpManager"> <property name="empDao" ref="empDao" /> </bean>
EmpDao의 bean을 inject
public class EmpManager { private EmpDao empDao; public EmpDao getEmpDao() { return empDao; } public void setEmpDao(EmpDao empDao) { this.empDao = empDao; } ... }
이랬던 코드가~ 바뀐다.
After
applicationContext.xml에서 설정
<context:annotation-config /> <!-- 요거 꼭 빼먹지 말것 --> <bean id="empManager" class="autowiredexample.EmpManager" /> <bean id="empDao" class="autowiredexample.EmpDao" />
import org.springframework.beans.factory.annotation.Autowired; public class EmpManager { @Autowired private EmpDao empDao; }
Annotation을 써서 훨씬 보기에 간결한 코드를 짤 수 있다.
'나만의 작업 > Spring' 카테고리의 다른 글
| [Spring] @Autowired의 Before/After (2) | 2009/04/29 |
|---|---|
| [Spring] 스프링에서 VelocityTools 환경설정 (2) | 2008/03/20 |
| [Spring] 스프링 MVC를 이용한 웹 요청 처리 (4) | 2008/03/13 |
| [Spring] Bean과 BeanFactory의 후처리 (8) | 2008/02/12 |
| [Spring] 자동 묶기(Autowire) (2) | 2008/02/12 |
| [Spring] 세터 주입(Setter Injection)의 대안 (5) | 2008/02/05 |
| [Spring] 빈 묶기(Bean wiring) (2) | 2008/02/05 |
| [Spring] 스프링 컨테이너의 두 종류 (0) | 2008/02/05 |
| [Spring] Spring 환경설정 (4) | 2008/01/28 |
-
[NC]...YellOw2009/04/29 22:13 [Edit/Del] [Reply]인자 저도 스프링 공부해야하는데 요기서 많은 도움을 얻을 수 있을거 같네요!!
-
버리야2009/05/06 10:33 [Edit/Del]헷갈리는 일이 자주 생기시겠네용...ㅋㅋ
-


