<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<!-- 以上为头文件,主要注意一下编码 -->
<!-- lazy-init="true" 延迟加载 ,设置为lazy的bean将不会在ApplicationContext启动时提前被实例化,而是在第一次向容器通过getBean索取bean时实例化的。-->
<!-- 创建DataSource数据源(整合spring+proxool) -->
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<!-- 配置proxool连接池 -->
<property name="driverClassName" value="org.logicalcobwebs.proxool.ProxoolDriver" />
<property name="url" value="proxool.pools" />
</bean>
<!-- .如果在spring上要使用Struts中自带的上传功能必须在spring的配置文件中加以声明.否者将会出现:
java.lang.IllegalStateException: No LobHandler found for configuration - lobHandler property must be set on LocalSessionFactoryBean异常。配置如下: -->
<bean id="lobHandler" lazy-init="true" class="org.springframework.jdbc.support.lob.DefaultLobHandler" />
<!-- 创建sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 把数据源注入给session工厂-->
<property name="dataSource">
<ref bean="dataSource"/>
</property>
<!-- 配置hibernate属性 -->
<property name="hibernateProperties">
<props>
<!--针对MySql数据库的方言,特定的关系数据库生成优化的SQL -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!-- 是否在控制台打印sql语句 -->
<prop key="hibernate.show_sql">true</prop>
<!-- 输出格式化后的sql,更方便查看 -->
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 配置映射文件 -->
<property name="mappingResources">
<list>
<value>com/liwang/financial/model/Account.hbm.xml</value>
</list>
</property>
<!-- 在sessionFactory中注入lobHandler -->
<property name="lobHandler" ref="lobHandler" />
</bean>
<!-- 事务管理器,决定有谁提供事务管理,无论何种方式都需要 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 定义transactionManager,spring2.0声明事务。transaction-manager制定事务处理器 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 配置事务传播策略 -->
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="del*" propagation="REQUIRED" />
<tx:method name="load*" propagation="REQUIRED" />
<tx:method name="insert*" propagation="REQUIRED" />
<tx:method name="ajax*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 织入切面 -->
<aop:config>
<!-- 切入点 -->
<aop:pointcut id="allServiceMethod" expression="execution(* com.liwang.financial.*.service.*.*(..))" />
<!-- 在切点上织入切面 -->
<aop:advisor pointcut-ref="allServiceMethod" advice-ref="txAdvice" />
</aop:config>
<!-- 把DAO注入给Session工厂-->
<bean id="daoTemplate" abstract="true" lazy-init="true" p:sessionFactory-ref="sessionFactory" />
<!-- base -->
<bean id="AccountDaoImpl" class="com.liwang.financial.account.dao.impl.AccountDaoImpl" parent="daoTemplate" />
<!-- 引入 其它分支 -->
<import resource="applicationContext-tfg.xml" />
</beans>