关于spring中注入连接池,事务管理等有关的属性设置以后可能用得到

<!--spring配置-->
<?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/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    <bean id="propertyConfigurer"
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath:jdbc.properties</value>           
            </list>
        </property>
    </bean>
    <!-- 连接池dbcp -->
    <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName"
            value="${driverClassName}">
        </property>
        <property name="url"
            value="${url}">
        </property>
        <property name="username" value="${username}"></property>
        <property name="password" value="${password}"></property>
        <!-- 最大 连接数 -->
        <property name="maxActive" value="100"></property>
        <!--最大空闲连接 -->
        <property name="maxIdle" value="30"></property>
        <!-- 最大等待连接 -->
        <property name="maxWait" value="500"></property>
        <!-- 默认最大提交,TRUE,每操作一次数据库自动提交
        <property name="defaultAutoCommit" value="true"></property>-->
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
        <property name="hibernateProperties">
            <props>
                <!--ernate方言-->
                <prop key="hibernate.dialect">
                    ${dialec}
                </prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">none</prop>
                <prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
                <!--统计信息 -->
                <prop key="generate_statistics">false</prop>
                <!-- Query查询时也用二级缓存
                <prop key="cache.use_query_cache">true</prop>-->
            </props>
        </property>
        <!--  <property name="mappingResources">
            <list>
            <value>com/test/bean/User.hbm.xml</value>
            </list>
            </property>-->
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
       
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>

    <!-- 配置事务的传播特性 -->
    <tx:advice id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
           
            <tx:method name="add*" propagation="REQUIRED"/>
            <tx:method name="del*" propagation="REQUIRED"/>
            <tx:method name="update*" propagation="REQUIRED"/>
            <tx:method name="save*" propagation="REQUIRED"/>
            <tx:method name="find" read-only="true"/>
        </tx:attributes>
    </tx:advice>

    <!-- 配置哪些类哪些方法使用事务 -->
    <aop:config>
        <aop:pointcut id="allManagerMethod"
            expression="execution(* com.teamsun.drp.service.*.*(..))"/>
        <aop:advisor advice-ref="txAdvice"
            pointcut-ref="allManagerMethod"/>
    </aop:config>
</beans>


<!--Dao-->
    /**
    * 增加用户信息
    */
    public Boolean addUser(TblDrpUser entity) throws HibernateException {
        Boolean flag =false;
        try{
            this.getHibernateTemplate().saveOrUpdate(entity);
            flag =true;
        }catch(Exception e){
            e.printStackTrace();
            thrownew HibernateException("添加用户信息出错!");
        }
        return flag;
    }
原文地址:https://www.cnblogs.com/sailormoon/p/2826679.html