<!-- lang: 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:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/new"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="com/mydomain/data/SqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 第一种将sqlMapClient直接注入到dao实现类中,并继承SqlMapClientDaoSupport dao实现类继承自SqlMapClientDaoSupport-->
<!-- <bean id="accountDao" class="example.SqlMapAccountDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean> -->
<!-- 第二种将sqlMapClient直接注入到sqlMapClientDaoSupport实现类中将sqlMapClientDaoSupport的bean定义为抽象,dao的bean利用parent继承抽象bean sqlMapClientDaoSupport,dao类继承SqlMapClientDaoSupport dao实现类继承自SqlMapClientDaoSupport-->
<!-- <bean id="sqlMapClientDaoSupport" class="org.springframework.orm.ibatis.support.SqlMapClientDaoSupport" abstract="true">
<property name="sqlMapClient" ref="sqlMapClient" />
</bean>
<bean id="accountDao" class="example.SqlMapAccountDao" parent="sqlMapClientDaoSupport">
</bean> -->
<!-- 第三种定义一个抽象bean,有一个属性为工厂类,即sqlMapClient,在使dao bean继承abstractDao bean,dao实现类继承自SqlMapClientDaoSupport-->
<!-- <bean id="abstractDao" abstract="true" >
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean> <bean id="accountDao" class="example.SqlMapAccountDao" parent="abstractDao"> </bean> --> <!-- 第四种将sqlMapClient直接注入到dao实现类中,并继承SqlMapClientTemplate bean继承自SqlMapClientTemplate--> <!-- <bean id="accountDao" class="example.SqlMapAccountTemplateDao"> <property name="sqlMapClient" ref="sqlMapClient"/> </bean> --> <!-- 第五种将sqlMapClient直接注入到sqlMapClientTemplate,并继承SqlMapClientTemplate bean继承自SqlMapClientTemplate,同第二种--> <!-- <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" abstract="true"> <property name="sqlMapClient" ref="sqlMapClient" /> </bean> <bean id="accountDao" class="example.SqlMapAccountTemplateDao" parent="sqlMapClientTemplate"> </bean> --> <!-- 第六种定义一个抽象bean,有一个属性为工厂类,即sqlMapClient,在使dao bean继承abstractDao bean,dao实现类继承自SqlMapClientTemplate--> <!-- <bean id="abstractDao" abstract="true" > <property name="sqlMapClient" ref="sqlMapClient"/> </bean> <bean id="accountDao" class="example.SqlMapAccountTemplateDao" parent="abstractDao"> </bean> --> <!-- 第七种手动在dao实现类中定义一个SqlMapClientTemplate的属性,提供set方法,并对其进行注入sqlMapClientTemplate,并将sqlMapClient注入进SqlMapClientTemplate类中 --> <!-- <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" > <property name="sqlMapClient" ref="sqlMapClient" /> </bean> <bean id="accountDao" class="example.SqlMapAccountBaseDao" > <property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"/> </bean> --> <!-- 它没有类似于第二种的方式,因为它没有继承任何类 --> <!-- 第八种类似于第七种加第三种的的方式 --> <bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate" > <property name="sqlMapClient" ref="sqlMapClient" /> </bean> <bean id="abstractDao" abstract="true" > <property name="sqlMapClientTemplate" ref="sqlMapClientTemplate"/> </bean> <bean id="accountDao" class="example.SqlMapAccountBaseDao" parent="abstractDao"> </bean> <!-- 第九种是手动定义SqlMapClientDaoSupport为dao实现类的属性,并将sqlMapClient注入SqlMapClientDaoSupport中,配置和代码省略 --> <!-- 第十种是第九种变成抽象的,配置和代码省略 -->
</beans>