<!-- 加载 hibernate.properties 文件-->
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/jdbc.properties</value>
</property>
</bean>

 JDBC连接配置

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>com/ssh/bean/Person.hbm.xml</value>
</list>
</property>
</bean>

 连接池配置:

<!--c3p0 连接池-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${hibernate.connection.driver_class}</value>
</property>
<property name="jdbcUrl">
<value>${hibernate.connection.url}</value>
</property>
<property name="user">
<value>${hibernate.connection.username}</value>
</property>
<property name="password">
<value>${hibernate.connection.password}</value>
</property> <!-- 连接池中保留的最小连接数. -->
<property name="minPoolSize">
<value>5</value>
</property>
<!-- 连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize">
<value>100</value>
</property>
<!-- 初始化时获得的连接数,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize">
<value>5</value>
</property>
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime">
<value>60</value>
</property>
<!-- 当连接池中的连接耗尽的时候c3p0一次同时获得的连接数。Default: 3 -->
<property name="acquireIncrement">
<value>3</value>
</property> <!-- JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
  属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
  假如maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
<property name="maxStatements">
<value>0</value>
</property> <!-- 每60秒检查所有连接池中的空闲连接。Default: 0 -->
<property name="idleConnectionTestPeriod">
<value>60</value>
</property> <!-- 定义在从数据库获得新连接失败后反复尝试的次数。Default: 30 -->
<property name="acquireRetryAttempts">
<value>30</value>
</property> <!-- 获得连接失败将会引起所有等待连接池来获得连接的线程抛出异常。但是数据源仍有效
  保留,并在下次调用getConnection()的时候继续尝试获得连接。假如设为true,那么在尝试
  获得连接失败后该数据源将申明已断开并永久关闭。Default: false-->
<property name="breakAfterAcquireFailure">
<value>true</value>
</property> <!-- 因性能消耗大请只在需要的时候使用它。假如设为true那么在每个connection提交的
  时候都将校验其有效性。建议使用idleConnectionTestPeriod或automaticTestTable
  等方法来提升连接测试的性能。Default: false -->
<property name="testConnectionOnCheckout">
<value>false</value>
</property>
</bean>
<!--create sessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource"></property>
  <!-- config hibernate Field -->
  <property name="hibernateProperties">
<props>
<prop key="hibernate.dialect"> ${hibernate.dialect}</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.jdbc.fetch_size"> ${hibernate.jdbc.fetch_size}</prop>
<prop key="hibernate.jdbc.batch_size"> ${hibernate.jdbc.batch_size}</prop>
<prop key="hibernate.current_session_context_class">thread</prop>
<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
<prop key="hibernate.query.substitutions">true</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.hibernate.use_outer_join">true</prop>
<prop key="hibernate.jdbc.batch_size">50</prop> <!-- prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop --> <!-- 自动增加新表,重新启动服务时执行该命令,应用时务必注释此句(本机使用) -->
<!-- prop key="hibernate.hbm2ddl.auto">update</prop -->
</props>
  </property>
  <!--mapping hibernate model po class-->
  <property name="mappingDirectoryLocations">
<list>
  <value>/WEB-INF/classes/com/cms/pojo</value><!--改文件夹下面的所有的配置文件 -->
</list>
  </property>
</bean>

 事务配置方法一: 

<!-- 定义事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 配置事务管理器 -->
<property name="transactionManager" ref="transactionManager"></property>
<!-- 配置事务属性 -->
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<list>
<value>PersonDAOImpl</value>
</list>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>

 事务配置方法二:

<!--config transaction manager-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- Transactional advice -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" />
<tx:method name="update*" />
<tx:method name="delete*" />
<tx:method name="add" />
<tx:method name="modify*" />
<tx:method name="remove*"/>
<tx:method name="merge*" />
<!-- <tx:method name="list*" /> -->
<!-- <tx:method name="ajax*" /> -->
<!-- other methods are set to read only -->
<!-- tx:method name="*" read-only="true"/ -->
</tx:attributes>
</tx:advice>

  

applicationContext.xml重要配置的更多相关文章

  1. SSH整合,applicationContext.xml中配置hibernate映射文件问题

    今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...

  2. spring-mvc.xml 和 application-context.xml的配置与深入理解

    在java框架这个话题,前几篇文章是基于搭建ssm项目框架,以及web.xml的配置讲解,本篇主要就ssm框架的其他配置文件进行深入讲解,他们分别是:1.application-context.xml ...

  3. applicationContext.xml的配置

    想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好).以至于有的初学者都不知道Spring配置文件的意思,就拿来用了.所以今天我给大家详 ...

  4. 在application-context.xml中配置多个property-placeholder

    如下所示,直接写多个<context:property-placeholder>标签是会报错的. <context:property-placeholder location=&qu ...

  5. SSH applicationContext.xml文件配置

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  6. applicationContext.xml文件配置模板

    <?xml version="1.0" encoding="gb2312"?><!--  Spring配置文件的DTD定义-->< ...

  7. spring +springmvc+mybatis组合applicationContext.xml文件配置

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  8. SSH框架整合--applicationContext.xml文件配置实例

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

  9. applicationContext.xml 基本配置

    <!-- 头文件,主要注意一下编码 --><?xml version="1.0" encoding="UTF-8"?><beans ...

  10. ssh2学习-applicationContext.xml文件配置-----<context:annotation-config/>详解

    当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredA ...

随机推荐

  1. 51nod1640 【最小生成树】

    题意: 在一副图中,搞N-1条边,使得每个点都相连, 有多种可能的情况,所以求一种使得其中n-1条边的最大是所有可能的最小,然后并保证连接的n-1条边的权值总和最大 思路: 一开始没有看清题意,随便写 ...

  2. __enter__,__exit__

    目录 上下文管理协议 模拟open 优点 我们知道在操作文件对象的时候可以这么写 with open('a.txt') as f: '代码块' 上述叫做上下文管理协议,即with语句,为了让一个对象兼 ...

  3. 类的property特性

    目录 什么是 property特性 简单示例 property属性的两种方式 装饰器 类属性方式 property+类的封装 应用 私有属性添加getter和setter方法 使用property升级 ...

  4. PostgreSQL-3-DDL数据定义语言

    1.创建/删除新的数据库 \l  查看现有数据库 \h CREATE DATABASE  查看CREATE DATABASE语句说明 \h DROP DATABASE 查看DROP DATABASE语 ...

  5. [题解]luogu_AT1224_JOIOJI

    https://www.cnblogs.com/fengzhiyuan/p/7588443.html 不会map,有点菜 1.要想知道三个字母出现次数相等, 为J [ i ]-J [ j ]== O[ ...

  6. Zynq7000开发系列-6(QT开发环境搭建:Ubuntu、Zynq)

    操作系统:Ubuntu14.04.5 LTS 64bit Qt:Qt 5.4.2 (qt-opensource-linux-x64-5.4.2.run.qt-everywhere-opensource ...

  7. Tinghua Data Mining 7

    SVM B分割得更加无偏 比较公平 卡着分界面的点叫支持向量,就好比托着分界面 支持向量决定了可移动的范围,这个范围就叫margin 分界面可移动的距离 前提是先要被分对 对偶问题一般是不等价的,但是 ...

  8. Day2课后作业:sed替换程序

    #!/usr/bin/env python #_*_conding:utf-8_*_ import sys,os old_file = sys.argv[1] new_file = sys.argv[ ...

  9. 104 Maximum Depth of Binary Tree 二叉树的最大深度

    给定一个二叉树,找出其最大深度.二叉树的深度为根节点到最远叶节点的最长路径上的节点数.案例:给出二叉树 [3,9,20,null,null,15,7],    3   / \  9  20    /  ...

  10. 安装gnvm (windows下nodejs版本管理工具)

    一些写在前面的话,为什么装这个?前两天看avalon视频的时候,里面有介绍去哪儿的前端构建工具fekit.我这人吧,好奇心特别强,就打算安装用用看.在安装时它提示要求node版本0.8.x,所以我选择 ...