img
Note In previous sections, all the sample code uses the XML type configuration. So, in the following sections,
we will use Spring annotations for ApplicationContext configuration. In case you decide to adopt XML
configuration in your application, we believe you will have a good idea of how to do it.
Setting Up JDBC DAO Using Annotations
First let's take a look on how to set up the DAO implementation class using annotations first. Listing 8-32
shows the ContactDao interface class with a more complete listing of the data access services it provides.
Listing 8-32. ContactDao Interface
package com.apress.prospring3.ch8.dao;
// Import statements omitted
public interface ContactDao {
public List<Contact> findAll();
public List<Contact> findAllWithDetail();
public List<Contact> findByFirstName(String firstName);
public String findFirstNameById(Long id);
public String findLastNameById(Long id);
public void insert(Contact contact);
public void update(Contact contact);
public void delete(Long contactId);
}
In Listing 8-33, the initial declaration and injection of the data source property using the JSR-250
annotation was shown. The class name is JdbcContactDao, but this time we put it under the package
com.apress.prospring3.ch8.dao.jdbc.annotation.
Listing 8-33. Declaring JdbcContactDao Using Annotations
package com.apress.prospring3.ch8.dao.jdbc.annotation;
import javax.annotation.Resource;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Repository;
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home