SSH中 c3po 配置和事务处理配置(注解方式)

来源:互联网 发布:多人直播源码 编辑:程序博客网 时间:2024/06/09 16:00
  1.     <!-- 配置SessionFactory IOC-->  
  2.     <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  
  3.         <!-- 指定hibernate的配置文件位置 -->  
  4.         <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>  
  5.         <!-- 配置c3p0数据库连接池 -->  
  6.           
  7.         <property name="dataSource">  
  8.             <bean class="com.mchange.v2.c3p0.ComboPooledDataSource">  
  9.                 <!-- 数据连接信息 -->  
  10.                 <property name="jdbcUrl" value="${jdbcUrl}"></property>  
  11.                 <property name="driverClass" value="${driverClass}"></property>  
  12.                 <property name="user" value="${user}"></property>  
  13.                 <property name="password" value="${password}"></property>  
  14.                   
  15.                 <!-- 其他配置 -->  
  16.                 <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->  
  17.                 <property name="initialPoolSize" value="3"></property>  
  18.                 <!--连接池中保留的最小连接数。Default: 3 -->  
  19.                 <property name="minPoolSize" value="3"></property>  
  20.                 <!--连接池中保留的最大连接数。Default: 15 -->  
  21.                 <property name="maxPoolSize" value="5"></property>  
  22.                 <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->  
  23.                 <property name="acquireIncrement" value="3"></property>  
  24.                 <!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->  
  25.                 <property name="maxStatements" value="8"></property>  
  26.                 <!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->  
  27.                 <property name="maxStatementsPerConnection" value="5"></property>  
  28.                 <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->  
  29.                 <property name="maxIdleTime" value="1800"></property>  
  30.             </bean>  
  31.         </property>  
  32.     </bean>  
  33.   
  34.   
  35.     <!-- 配置声明式事务管理(采用注解的方式) AOP-->  
  36.     <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  37.         <property name="sessionFactory" ref="sessionFactory"></property>  
  38.     </bean>  
  39.     <!-- 注解驱动-->  
  40.     <tx:annotation-driven transaction-manager="txManager"/>  
  41.    
  42.   
0 0
原创粉丝点击