import com.apress.prospring3.ch8.dao.ContactDao;
@Repository("contactDao")
public class JdbcContactDao implements ContactDao {
private Log log = LogFactory.getLog(JdbcContactDao.class);
private DataSource dataSource;
@Resource(name="dataSource")
public void setDataSource(DataSource dataSource) {
this.dataSource = dataSource;
}
public DataSource getDataSource() {
return dataSource;
}
}
In the previous listing, we use the @Repository to declare the Spring bean with a name of contactDao,
and since the class contains data access code, the @Repository also instructs Spring to perform database-
specific SQL exceptions to the more application-friendly DataAccessException hierarchy in Spring.
We also declare the log variable using Apache commons-logging to log the message within the
program. And for the datasource property, we use JSR-250's @Resource to let Spring inject the data
source with a name of dataSource.
We are going to implement the methods in the ContactDao interface one by one. In the meantime,
let's first create an empty implementation of all the methods in the JdbcContactDao class. An easy way to
do this is using STS to generate empty implementations on our behalf. In STS, right-click the class and
select Source Override/Implement Methods (see Figure 8-2).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home