springMVC中bean容器:bean.xml的配置

2023-05-16

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    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.0.xsd
                            http://www.springframework.org/schema/context
                            http://www.springframework.org/schema/context/spring-context-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/aop
                            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
    <!-- 1.添加组件对注解的支持:扫描 -->
    <context:component-scan base-package="com.lovo.elec"></context:component-scan>
    <!-- 2.C3P0连接池 (另一种还有dbcp) -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <!-- &的转义字符:&amp; -->
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/elec_u16?useUnicode=true&amp;characterEncoding=utf-8"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
        <!-- 连接池中保留的最小连接数。 -->
        <property name="minPoolSize" value="5"></property>
        <!-- 连接池中保留的最大连接数。Default: 15 -->
        <property name="maxPoolSize" value="30"></property>
        <!-- 初始化时获取的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
        <property name="initPoolSize" value="10"></property>
        <!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
        <property name="maxIdleTime" value="60"/>
        <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
        <property name="acquireIncrement" value="5" />
        <!--定义在从数据库获取新连接失败后重复尝试的次数。Default: 30-->
        <property name="acquireRetryAttempts" value="30" />
        <!-- 获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常。但是数据源仍有效  
              保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试  
              获取连接失败后该数据源将申明已断开并永久关闭。Default: false -->
        <property name="breakAfterAcquireFailure" value="true" />
    </bean>         
    <!-- 3.创建sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property>
            <property name="configLocation">
                <value>
                    classpath:hibernate.cfg.xml
                </value>
            </property>
        <property name="dataSource" ref="dataSource"/>
    </bean>              
    <!-- 4.创建事务管理器 -->
    <bean id="transManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>                        
    <!-- 5.事务处理:注解 -->
    <tx:annotation-driven transaction-manager="transManager" />
    <!-- 事务处理:配置文件 -->
    <!--
        <tx:advice id="adviceBean" transaction-manager="trManager">
        <tx:attributes> <tx:method name="save*" isolation="DEFAULT"
        propagation="REQUIRED" read-only="false"/> <tx:method name="update*"
        isolation="DEFAULT" propagation="REQUIRED" read-only="false"/>
        <tx:method name="delete*" isolation="DEFAULT" propagation="REQUIRED"
        read-only="false"/> <tx:method name="*" read-only="true"/>
        </tx:attributes> </tx:advice> <aop:config> <aop:pointcut
        expression="execution(* cn.lovo.elec.service..*.*(..))"
        id="pointcutBean"/> <aop:advisor advice-ref="adviceBean"
        pointcut-ref="pointcutBean"/> </aop:config>
    -->
</beans>                            

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

springMVC中bean容器:bean.xml的配置 的相关文章

随机推荐