출처 : http://www.mungchung.com/
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; } |
'프로그래밍 > Spring & MyBatis' 카테고리의 다른 글
[Spring Framework] Spring MVC (0) | 2018.12.10 |
---|---|
[Spring Framework] @Transactional 트랜젝션 관리 (0) | 2018.12.10 |
[Spring Boot] 첨부파일 (0) | 2018.12.06 |
[Spring] 어노테이션 Annotation (0) | 2018.12.06 |
[Spring] logback 사용하기 (0) | 2018.12.06 |