<?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:aop = "http://www.springframework.org/schema/aop"
xmlns:tx ="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd" default-lazy-init="true">
<!-- 定义数据源的bean,给Hibernate的sessionFactory ,dbcp是连接池的包,还需要加pool的jar包连接池才能生效-->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="oracle.jdbc.driver.OracleDriver">
</property>
<!-- 定义数据连接的url -->
<property name="url"
value="jdbc:oracle:thin:@10.2.2.117:1521:....">
</property>
<property name="username" value="....."></property>
<property name="password" value="...."></property>
</bean>
<!-- 定义Hibernate的sessionFactory,通过该bean,可以获得Hibernate的sessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<!-- 设置数据库方言 -->
<prop key="hibernate.dialect">
org.hibernate.dialect.Oracle9Dialect
</prop>
<!-- 设置二级的查询缓冲 -->
<prop key="hibernate.cache.provider_class">
org.hibernate.cache.EhCacheProvider
</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<!-- 控制台是否输出SQL语句 -->
<!-- 设置显示Hibernate操作的sql语句 -->
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<!-- 配置映射文件 -->
<property name="mappingResources">
<list>
<value>com/gxmis/acc/pojo/WhUser.hbm.xml</value>
<value>com/gxmis/acc/pojo/WhCodingContent.hbm.xml</value>
<value>com/gxmis/acc/pojo/YySystemVersionReg.hbm.xml</value>
<value>com/gxmis/acc/pojo/YySystemVersion.hbm.xml</value>
<value>com/gxmis/acc/pojo/YySystemVersionHis.hbm.xml</value>
<value>com/gxmis/acc/pojo/WhFunction.hbm.xml</value>
<value>com/gxmis/acc/pojo/YyEquipment.hbm.xml</value>
</list>
</property>
</bean>
<!-- 配置DAO层中的实现类 的bean-->
<!-- 为WhUser配置的bean -->
<bean id="whuserDao" class="com.gxmis.acc.dao.impl.WhUserDAO">
<!-- 属性sessionFactory是通过spring注射进来的,引用了当前的sessionFactory(在这个文件的上一个bean中配置了) -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="whuserService" class="com.gxmis.acc.service.impl.WhUserService">
<property name="userDao" ref="whuserDao"></property>
</bean>
<!-- 为Login配置的bean -->
<bean id="loginAction" class="com.gxmis.acc.action.LoginAction" scope="prototype">
<property name="userService" ref="whuserService"></property>
</bean>
<!-- 为WhCodingContent配置的bean -->
<bean id="whcodingcontentDao" class="com.gxmis.acc.dao.impl.WhCodingContentDAO">
<!-- 属性sessionFactory是通过spring注射进来的,引用了当前的sessionFactory(在这个文件的上一个bean中配置了) -->
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="whcontentService" class="com.gxmis.acc.service.impl.WhContentService">
<property name="contentDAO" ref="whcodingcontentDao"></property>
</bean>
......
......
......
<!-- 以上主要是持久层的一些配置 -->
<!-- 以下是事务控制层的配置(比较固定的,3个bean) -->
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>
<!-- 配置事务特性,配置以以下字母开始的方法(insert,remove和update)的事务传播特性为required (如果存在一个事务,则支持当前事务。如果没有事务则开启一个新事务 )-->
<!-- tx标签是spring提供的,文件为spring目录下的dst.resource.spring-tx-2.0.xsd -->
<!-- 一开始不识别标签的原因是因为在文件头没有加入引用,当一个标签不可用的时候首先要确认库中是否加载了标签 ,然后看文件中有没有加入引用(引用的名称去库中看windows.preferences.myEclipse.files and editors.xml.xml catalog)-->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="find*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
<!-- 配置哪些类的方法进行事务管理,当前的mcm.acc.service包中的子包,类中的所有方法需要,还有 就是需要参考tx:advice中的设置-->
<aop:config>
<aop:pointcut id="allManagerMethod" expression="execution(* com.gxmis.acc.service.impl.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="allManagerMethod"/>
</aop:config>
</beans>
(By:Gxmis-alextang)