<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- define basic datasource by apache dbcp
虽然hibernate的高级版本已经明确的指出对dbcp不再提供支持,但是就开发阶段来说,
使用dbcp配置数据源未曾不可.....
-->
<bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/schooldb?characterEncoding=utf-8" />
<property name="username" value="root" />
<property name="password" value="123456"/>
</bean>
<!-- define transaction aware data source proxy
定义proxy,是spring感知数据源....
-->
<bean id="transactionAwareDataSourceProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg>
<ref bean="basicDataSource" />
</constructor-arg>
</bean>
<!-- define session factory by transaction aware data source proxy
使用spring support的sessionfactory 配合spring已经感知的数据源来定义sessionfactory...
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="transactionAwareDataSourceProxy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>mapping.hbm.xml</value>
</list>
</property>
</bean>
<!-- define dao by session factory
定义 data access object ,
次类需要 扩展 org.springframework.orm.hibernate3.support.HibernateDaoSupport...
-->
<bean id="hibernateBasedDAO" class="com.gmail.chrnc0000.hibernate.HibernateBasedDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- define spring transaction manager by session factory -->
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--
定义 spring interceptor ,并且对需要回滚的异常进行配置...
-->
<bean id="transactionProxyFactoryBean" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="hibernateTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- define service
定义interceptor 配合的 service ...
-->
<bean id="transactionProxyBasedService" parent="transactionProxyFactoryBean">
<property name="target">
<bean class="com.gmail.chrnc0000.spring.TransactionProxyBasedService">
<property name="hibernateBasedDAO">
<ref local="hibernateBasedDAO" />
</property>
</bean>
</property>
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- define basic datasource by apache dbcp
虽然hibernate的高级版本已经明确的指出对dbcp不再提供支持,但是就开发阶段来说,
使用dbcp配置数据源未曾不可.....
-->
<bean id="basicDataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost/schooldb?characterEncoding=utf-8" />
<property name="username" value="root" />
<property name="password" value="123456"/>
</bean>
<!-- define transaction aware data source proxy
定义proxy,是spring感知数据源....
-->
<bean id="transactionAwareDataSourceProxy" class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
<constructor-arg>
<ref bean="basicDataSource" />
</constructor-arg>
</bean>
<!-- define session factory by transaction aware data source proxy
使用spring support的sessionfactory 配合spring已经感知的数据源来定义sessionfactory...
-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="transactionAwareDataSourceProxy" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>mapping.hbm.xml</value>
</list>
</property>
</bean>
<!-- define dao by session factory
定义 data access object ,
次类需要 扩展 org.springframework.orm.hibernate3.support.HibernateDaoSupport...
-->
<bean id="hibernateBasedDAO" class="com.gmail.chrnc0000.hibernate.HibernateBasedDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!-- define spring transaction manager by session factory -->
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
<!--
定义 spring interceptor ,并且对需要回滚的异常进行配置...
-->
<bean id="transactionProxyFactoryBean" lazy-init="true" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="hibernateTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED</prop>
<prop key="save*">PROPAGATION_REQUIRED,-Exception</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED,-Exception</prop>
</props>
</property>
</bean>
<!-- define service
定义interceptor 配合的 service ...
-->
<bean id="transactionProxyBasedService" parent="transactionProxyFactoryBean">
<property name="target">
<bean class="com.gmail.chrnc0000.spring.TransactionProxyBasedService">
<property name="hibernateBasedDAO">
<ref local="hibernateBasedDAO" />
</property>
</bean>
</property>
</bean>