<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "
http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="
dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>net.sourceforge.jtds.jdbc.Driver</value>
</property>
<property name="url">
<value>jdbc:jtds:sqlserver://127.0.0.1:1433/Sample</value>
</property>
<property name="username">
<value>test</value>
</property>
<property name="password">
<value>changeit</value>
</property>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation">
<value>SqlMapConfig.xml</value>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
<bean id="userDAO" class="net.xiaxin.dao.UserDAO">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="sqlMapClient">
<ref local="sqlMapClient" />
</property>
</bean>
<bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="userDAO" />
</property>
<property name="transactionAttributes">
<props>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
</beans>
1. sqlMapClient节点
类似SessionFactory之与Hibernate,这里我们引入了针对ibatis SqlMap的SqlMapClientFactoryBean配置。SqlMapClient对于ibatis的意义类似于Session与Hibernate以及Connection与JDBC,这里的sqlMapClient节点实际上配置了一个sqlMapClient的创建工厂类。configLocation属性配置了ibatis映射文件的名称。
2. transactionManager节点
这里我们的transactionManager配置与之前JDBC示例中相同,都采用了DataSourceTransactionManager,这与Hibernate有些差异。
3. userDAO节点
对应的,UserDAO需要配置两个属性,sqlMapClient和DataSource,sqlMapClient将从指定的DataSource中获取数据库连接。
posted on 2006-09-15 12:01
周锐 阅读(4744)
评论(0) 编辑 收藏 所属分类:
IBATIS 、
Spring