참고하세요~
1. XML 설정 파일에서
<!-- JdbcTemplate -->
<bean
id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"
p:dataSource-ref="dataSource" />
<!-- wire the
JdbcTemplate into your DAO (Alternatively, you could use autowiring)
-->
<bean id="boardDAO"
class="onj.board.dao.BoardDAOImpl"/>
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
>
<property
name="driverClassName">
<value>oracle.jdbc.driver.OracleDriver</value>
</property>
<property
name="url">
<value>jdbc:oracle:thin:@192.168.0.17:1521:onj</value>
</property>
<property
name="username">
<value>scott</value>
</property>
<property
name="password">
<value>tiger</value>
</property>
</bean>
2. DAO 자바파일에서
@Repository("boardDAO")
public class BoardDAOImpl implements BoardDAO {
@Autowired
private JdbcOperations jdbcTemplate;
또는
@Autowired
private JdbcTemplate jdbcTemplate;
.................................
또는 아래처럼 setter를 만들어서... 세터주입으로
//아래 두개의 어떤 타입으로 받아도 된다.
//private
JdbcOperations jdbcTemplate;
private
JdbcTemplate jdbcTemplate;
public void
setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
댓글 없음:
댓글 쓰기