三大框架整合文件配置

来源:互联网 发布:java怎么调用函数 编辑:程序博客网 时间:2024/05/20 07:19
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
    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-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <!-- 配置数据源,使用c3p0实现 -->
    <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <!-- 配置数据库驱动 -->
        <property name="driverClass">
            <value>com.mysql.jdbc.Driver</value>
        </property>
        <!-- 数据库连接字符串 -->
        <property name="jdbcUrl">
            <value>jdbc:mysql://localhost:3306/ssh</value>
        </property>
        <!-- 数据库用户名 -->
        <property name="user">
            <value>root</value>
        </property>
        <!-- 数据库密码 -->
        <property name="password">
            <value>sa</value>
        </property>
        <!-- 指定数据库连接池的初始化连接数 -->
        <property name="initialPoolSize" value="1" />
        <!-- 指定连接池中的连接最大空闲时间 -->
        <property name="maxIdleTime" value="20" />
        <!-- 最大连接数 -->
        <property name="maxPoolSize" value="40" />
        <!-- 最小连接数 -->
        <property name="minPoolSize" value="1" />
    </bean>
    
    <!-- 配置sessionFactory -->
    <bean name="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="configLocations">
            <list>
                <value>classpath:hibernate-cfg.xml</value>
            </list>
        </property>
    </bean>

    <!-- 配置hibernate的事务管理器 -->
    <bean name="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>
    
    <!-- 配置事务的特性  以save update delete remove 开始的方法,以事务的形式来操作,其他的以可有可无的的形式来操作-->
    <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="remove*" propagation="REQUIRED" />
            <tx:method name="get*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="query*" propagation="SUPPORTS" read-only="true" />
            <tx:method name="*" propagation="SUPPORTS" read-only="true" />
        </tx:attributes>
     </tx:advice>
    
    <!-- 配置哪些类的哪些方法执行事务管理 -->
    <aop:config>
      <aop:pointcut expression="execution(* com.huasoft.service..*.*(..))" id="allServiceMethod"/>
      <aop:advisor advice-ref="txAdvice" pointcut-ref="allServiceMethod"/>
    </aop:config>
    
 
</beans>
0 0