日期:2014-05-18 浏览次数:20780 次
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!--1. 配置数据源 --> <bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" singleton="false"> <property name="driverClassName" value="net.sourceforge.jtds.jdbc.Driver"/> <property name="url" value="jdbc:jtds:sqlserver://localhost:1433/EE"/> <property name="username" value="sa"/> <property name="password" value="1234"/> </bean> <!--2. 配置sqlMapClient 相当于hibernate的sessionFactory --> <bean id="mySqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean"> <property name="configLocation" value="ibatisConfig/ibatisConfig.xml"/> <property name="dataSource" ref="myDataSource"/> </bean> <!--3. 配置DAO --> <bean id="userDaoAtXml" class="cn.luyu.ssi.dao.Impl.UserDaoImpl"> <property name="dataSource" ref="myDataSource"/> <property name="sqlMapClient" ref="mySqlMapClient"/> </bean> <!--4. 配置服务类 --> <bean id="userServiceTarget" class="cn.luyu.ssi.service.Impl.UserServiceImpl"> <property name="userDao" ref="userDaoAtXml"/> </bean> <!--5. 配置事务管理器TransactionManager --> <bean id="myTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="myDataSource"/> </bean> <!--6. 配置事务代理 --> <bean id="abstrac" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true"> <property name="transactionManager" ref="myTransactionManager"/> <property name="transactionAttributes"> <props> <!--把CustomBuyException减去.说明它即使不是runtimeException,也会rollback--> <!--把CustomBuyException加上.说明它即使是runtimeException,也不会rollback--> <prop key="*">-DataAccessException</prop> </props> </property> </bean> <!-- 继承abstrac 方便多个service来映射 --> <bean id="userService" parent="abstrac"> <property name="target" ref="userServiceTarget"/> </bean> </beans>