接下来,看看applicationContext.xml文件
利用PropertyPlaceholderConfigurer类关联资源文件,用$(...)的方式索引各个属性,例如,$(jdbc.url)可以取得资源文件中jdbc.url所设定的值.
声明bean petStore,感觉这里是将上述的五个DAO的bean注入PetStore方法接口的实现类PetStoreImpl中,用于持久层操作.
声明式事务配置,详细介绍可参照另一篇笔记
spring框架的事务管理
接下来是dataAccessContext-local.xml文件
声明数据源bean
声明事务的资源管理类
此处声明ibatis的配置map 文件的位置
定义DAO的bean,为接口实现类配置注入sqlMapClient的bean这里只贴一个,其他类似。
<
bean
id
="propertyConfigurer"
class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
< property name ="locations" >
< list >
< value > WEB-INF/mail.properties </ value >
< value > WEB-INF/jdbc.properties </ value >
</ list >
</ property >
</ bean >
class ="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
< property name ="locations" >
< list >
< value > WEB-INF/mail.properties </ value >
< value > WEB-INF/jdbc.properties </ value >
</ list >
</ property >
</ bean >
<
bean
id
="petStore"
class
="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl"
>
< property name ="accountDao" ref ="accountDao" />
< property name ="categoryDao" ref ="categoryDao" />
< property name ="productDao" ref ="productDao" />
< property name ="itemDao" ref ="itemDao" />
< property name ="orderDao" ref ="orderDao" />
</ bean >
< property name ="accountDao" ref ="accountDao" />
< property name ="categoryDao" ref ="categoryDao" />
< property name ="productDao" ref ="productDao" />
< property name ="itemDao" ref ="itemDao" />
< property name ="orderDao" ref ="orderDao" />
</ bean >
<
aop:config
>
< aop:advisor pointcut ="execution(* *..PetStoreFacade.*(..))" advice-ref ="txAdvice" />
</ aop:config >
< tx:advice id ="txAdvice" transaction-manager ="transactionManager" >
< tx:attributes >
< tx:method name ="insert*" />
< tx:method name ="update*" />
< tx:method name ="*" read-only ="true" />
</ tx:attributes >
</ tx:advice >
< aop:advisor pointcut ="execution(* *..PetStoreFacade.*(..))" advice-ref ="txAdvice" />
</ aop:config >
< tx:advice id ="txAdvice" transaction-manager ="transactionManager" >
< tx:attributes >
< tx:method name ="insert*" />
< tx:method name ="update*" />
< tx:method name ="*" read-only ="true" />
</ tx:attributes >
</ tx:advice >
接下来是dataAccessContext-local.xml文件
<
bean
id
="dataSource"
class
="org.apache.commons.dbcp.BasicDataSource"
destroy-method
="close"
>
< property name ="driverClassName" value ="${jdbc.driverClassName}" />
< property name ="url" value ="${jdbc.url}" />
< property name ="username" value ="${jdbc.username}" />
< property name ="password" value ="${jdbc.password}" />
</ bean >
< property name ="driverClassName" value ="${jdbc.driverClassName}" />
< property name ="url" value ="${jdbc.url}" />
< property name ="username" value ="${jdbc.username}" />
< property name ="password" value ="${jdbc.password}" />
</ bean >
<
bean
id
="transactionManager"
class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name ="dataSource" ref ="dataSource" />
</ bean >
class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name ="dataSource" ref ="dataSource" />
</ bean >
<
bean
id
="sqlMapClient"
class
="org.springframework.orm.ibatis.SqlMapClientFactoryBean"
>
< property name ="configLocation" value ="WEB-INF/sql-map-config.xml" />
< property name ="dataSource" ref ="dataSource" />
</ bean >
< property name ="configLocation" value ="WEB-INF/sql-map-config.xml" />
< property name ="dataSource" ref ="dataSource" />
</ bean >
<
bean
id
="accountDao"
class
="org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao"
>
< property name ="sqlMapClient" ref ="sqlMapClient" />
</ bean >
< property name ="sqlMapClient" ref ="sqlMapClient" />
</ bean >