applicationContext.xml重要配置
<!-- 加载 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重要配置的更多相关文章
- SSH整合,applicationContext.xml中配置hibernate映射文件问题
今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...
- spring-mvc.xml 和 application-context.xml的配置与深入理解
在java框架这个话题,前几篇文章是基于搭建ssm项目框架,以及web.xml的配置讲解,本篇主要就ssm框架的其他配置文件进行深入讲解,他们分别是:1.application-context.xml ...
- applicationContext.xml的配置
想必用过Spring的程序员们都有这样的感觉,Spring把逻辑层封装的太完美了(个人感觉View层封装的不是很好).以至于有的初学者都不知道Spring配置文件的意思,就拿来用了.所以今天我给大家详 ...
- 在application-context.xml中配置多个property-placeholder
如下所示,直接写多个<context:property-placeholder>标签是会报错的. <context:property-placeholder location=&qu ...
- SSH applicationContext.xml文件配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- applicationContext.xml文件配置模板
<?xml version="1.0" encoding="gb2312"?><!-- Spring配置文件的DTD定义-->< ...
- spring +springmvc+mybatis组合applicationContext.xml文件配置
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- SSH框架整合--applicationContext.xml文件配置实例
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...
- applicationContext.xml 基本配置
<!-- 头文件,主要注意一下编码 --><?xml version="1.0" encoding="UTF-8"?><beans ...
- ssh2学习-applicationContext.xml文件配置-----<context:annotation-config/>详解
当我们需要使用BeanPostProcessor时,直接在Spring配置文件中定义这些Bean显得比较笨拙,例如: 使用@Autowired注解,必须事先在Spring容器中声明AutowiredA ...
随机推荐
- hdoj2577【多种状态】(简单DP)
#include <stdio.h> #include <iostream> #include <sstream> #include <string.h> ...
- MongoDb Samus 驱动的改进
一直使用 MongoDb 的 Samus C#驱动. 其有一个缺陷,就是无法支持struct的读写. 但是一般数据都用Class包装,所以也没有太在意. 随着这些天尝试写入 KLineData 时,遇 ...
- Node.js 关于module的一些认知
module是一个对象,在Node环境中运行js脚本,module会自动添加,并且系统会将函数封装到另一个函数中 例如: var module = { id: '.', exports: {} }; ...
- Bug调试(lldb)
原文网址:http://www.cnblogs.com/Twisted-Fate/p/4760156.html 今天博主有一些Bug调试的需求,遇到了一些困难点,在此和大家分享,希望能够共同进步. X ...
- 第二篇 Nosql讲解之windows下memcache的安装(一)
memcached基本概念 1.Memcached是danga的一个项目,最早是LiveJournal服务的,最初为了加速LiveJournal访问速度而开发的,后来被很多大型的网站采用. 官方网站: ...
- Info.plist配置相关文件访问权限
<key>NSAppleMusicUsageDescription</key> <string>App需要您的同意,才能访问媒体资料库</string> ...
- [题解](次短路)luogu_P2865路障(未)
好像是个不需要vis数组的次短路,跑到收敛,然而给我脑袋弄炸了......到现在还没懂.......究竟次短路应该怎么求a...... 抄题解: #include<bits/stdc++.h&g ...
- JS的this原理
转载阮一峰博客: www.ruanyifeng.com/blog/2018/06/javascript-this.html 一.问题的由来 学懂 JavaScript 语言,一个标志就是理解下面两 ...
- STM32F4之SWO
https://stm32f4-discovery.net/2014/12/library-46-debug-stm32f4-device-swo-feature/
- Java中的if-else语句——通过示例学习Java编程(7)
作者:CHAITANYA SINGH 来源:https://www.koofun.com/pro/kfpostsdetail?kfpostsid=18 当我们需要根据一个条件执行一组语句时,我们需 ...