[Spring] @Autowired의 Before/After

Posted at 2009/04/29 15:35// Posted in 나만의 작업/Spring

Spring framework 2.5에 추가된 @Autowired annotation에 관한 글을 보고 정리.

알고있는 내용이기에~ 그냥 가볍게 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을 써서 훨씬 보기에 간결한 코드를 짤 수 있다.









  1. [NC]...YellOw
    2009/04/29 22:13 [Edit/Del] [Reply]
    인자 저도 스프링 공부해야하는데 요기서 많은 도움을 얻을 수 있을거 같네요!!

댓글을 남겨주세요

Name *

Password *

Link (Your Homepage or Blog)

Comment

Secret