spring JpetStore学习笔记(三)

 接下来,看看applicationContext.xml文件
< 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 >
利用PropertyPlaceholderConfigurer类关联资源文件,用$(...)的方式索引各个属性,例如,$(jdbc.url)可以取得资源文件中jdbc.url所设定的值.

< 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 >
声明bean petStore,感觉这里是将上述的五个DAO的bean注入PetStore方法接口的实现类PetStoreImpl中,用于持久层操作.

< 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 >
声明式事务配置,详细介绍可参照另一篇笔记 spring框架的事务管理


接下来是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 >
声明数据源bean

< bean  id ="transactionManager"
                 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 >
此处声明ibatis的配置map 文件的位置

< bean  id ="accountDao"  class ="org.springframework.samples.jpetstore.dao.ibatis.SqlMapAccountDao" >
        
< property  name ="sqlMapClient"  ref ="sqlMapClient" />
</ bean >
定义DAO的bean,为接口实现类配置注入sqlMapClient的bean这里只贴一个,其他类似。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值