1. xml 을 이용한 등록 방법 - setter 이용
1) applicationContext.xml
< bean id = "sqlMapClientTemplate" class = "org.springframework.orm.ibatis.SqlMapClientTemplate" > < property name = "sqlMapClient" ref = "sqlMapClient" /> </ bean > < bean id = "loginDAO" class = "com.mungchung.sample.login.LoginDAOImpl" > < property name = "sqlMapClientTemplate" ref = "sqlMapClientTemplate" /> </ bean >
|
2) Bean
public class LoginDAOImpl implements LoginDAO {
private SqlMapClientTemplate sqlMapClientTemplate; public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this .sqlMapClientTemplate = sqlMapClientTemplate;
} } |
2. xml 을 이용한 등록 방법 - 생성자 이용
1) applicationContext.xml
< bean id = "sqlMapClientTemplate" class = "org.springframework.orm.ibatis.SqlMapClientTemplate" > < property name = "sqlMapClient" ref = "sqlMapClient" /> </ bean > < bean id = "loginDAO" class = "com.mungchung.sample.login.LoginDAOImpl" > < constructor-arg name = "sqlMapClientTemplate" ref = "sqlMapClientTemplate" /> </ bean > |
2) Bean
public class LoginDAOImpl implements LoginDAO {
private SqlMapClientTemplate sqlMapClientTemplate; public LoginDAOImpl(SqlMapClientTemplate sqlMapClientTemplate) {
this .sqlMapClientTemplate = sqlMapClientTemplate;
} } |
3. 어노테이션 이용 - 직접 Bean 등록
1) servlet-context.xml
< context:annotation-config /> < bean id = "loginDAO" class = "com.mungchung.sample.login.LoginDAOImpl" />
|
2) Bean
public class LoginDAOImpl implements LoginDAO {
@Autowired private SqlMapClientTemplate sqlMapClientTemplate;
} |
4. 어노테이션 이용 - Component-Scan 이용
1) servlet-context.xml
< context:component-scan base-package = "com.mungchung.sample.login" />
|
2) Bean
@Repository public class LoginDAOImpl implements LoginDAO {
@Autowired private SqlMapClientTemplate sqlMapClientTemplate;
}
|
출처 : http://www.mungchung.com/xe/spring/21198
'Server Enterprise > Spring' 카테고리의 다른 글
[Servlet] redirect 와 forward 차이점 (0) | 2014.10.14 |
---|---|
[POM] Spring에서의 OJDBC dependency 방법 (Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver') (0) | 2014.10.14 |
[Interceptor] Spring MVC Session Check Interceptor (0) | 2014.02.27 |
[Spring] Context Root 변경 (0) | 2014.02.26 |
[Spring] 템플릿과 콜백 예제 (0) | 2013.07.21 |