Java Reference
In-Depth Information
Here's how we set up this file to get Spring to load components into its
container from our stripesbook.dao.impl.stripersist package:
Download email_25/web/WEB-INF/applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<context:component-scan
base-package="stripesbook.dao.impl.stripersist"/>
</beans>
Boy, that's a lot of cruft in the XML header, isn't it? Oh, well. Looking
past that, we see a single element where we're telling Spring to scan
a package and look for components. Now, we need give Spring a clue
about these components, which are our DAO implementations. Spring
provides four annotations to do this. @Component indicates a compo-
nent in general, while @Repository , @Service , and @Controller more pre-
cisely specify a persistence-, service-, or presentation-layer component.
@Repository is what we want since the DAOs are in the persistence layer,
so we use that annotation in the DAO implementation classes:
Download email_25/src/stripesbook/dao/impl/stripersist/ContactDaoImpl.java
@Repository("contactDao")
public class ContactDaoImpl extends BaseDaoImpl<Contact,Integer>
implements ContactDao
We're telling Spring that ContactDaoImpl is a persistence-layer compo-
nent named contactDao . We'll do the same for the other DAOs:
Download email_25/src/stripesbook/dao/impl/stripersist/AttachmentDaoImpl.java
@Repository("attachmentDao")
public class AttachmentDaoImpl extends BaseDaoImpl<Attachment,Integer>
implements AttachmentDao
Download email_25/src/stripesbook/dao/impl/stripersist/FolderDaoImpl.java
@Repository("folderDao")
public class FolderDaoImpl extends BaseDaoImpl<Folder,Integer>
implements FolderDao
 
Search WWH ::




Custom Search