- 浏览: 746769 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
lengzl:
请问,那个Node 是哪个包里面的类?
JAVA 二叉树的递归和非递归遍历 -
gongchuangsu:
总结的很好,感谢感谢
JAVA 二叉树的递归和非递归遍历 -
Caelebs:
666666666 居然是10年发的,难怪截屏自动保存的名字是 ...
截图工具 -
jijiqw:
是注解不是注释。。。
Spring @Transactional (一) -
letueo:
[b][b][b][b][b][b][b][b][b][b][ ...
Spring @Transactional (一)
源地址:http://www.iteye.com/t/18095.html
这些连接池的配置按照hibernate的文档配置没有问题,这段时间使用spring的时候配置的是c3p0的数据库连接池,
按照网上某些网友的介绍的配置,在日志中我没有看到连接池的初始化信息,为此自己研究,发现应该如此配置。
先我把配置写下,希望大家以后在配置的时候,不要再走弯路了
代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- ========================= Start of PERSISTENCE DEFINITIONS ========
================= -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"/>
<bean id="oracleLobHandle" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor"/>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="properties">
<props>
<prop key="c3p0.minPoolSize">${hibernate.c3p0.minPoolSize}</prop>
<prop key="hc3p0.maxPoolSize">${hibernate.c3p0.maxPoolSize}</prop>
<prop key="hc3p0.timeout">${hibernate.c3p0.timeout}</prop>
<prop key="c3p0.max_statement">${hibernate.c3p0.max_statement}</prop>
<prop key="c3p0.testConnectionOnCheckout">true</prop>
<prop key="user">${datasource.username}</prop>
<prop key="password">${datasource.password}</prop>
</props>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="lobHandler"><ref local="oracleLobHandle"/></property>
<property name="mappingResources">
<list>
<value>com/cs2c/oa2/pojo/Testfile.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.cglib.use_reflection_optimizer">${hibernate.cglib.use_reflection_optimizer}</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="test" class="com.cs2c.oa2.test.TestHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
在配置的时候 cp30的属性的名字必须是 ''driverClass' , 'jdbcUrl', 'user' , 'password' 而 <property name="properties">的名字也必须是“properties”,另外cp30配置文件的属性名也都是诸如:"c3p0.minPoolSize"、"hc3p0.maxPoolSize"等等,
java开源,希望大家也多多open,呵呵。我使用的是 spring1.2.6+hibernate3.1,ok,我觉得这些配置是基础知识,希望大家在今后一定要多看文档,在spring文档中有对dbcp如何配置,好了,不多说了。
自动重连的设置。
Configuring Recovery From Database Outages
c3p0 DataSources are designed (and configured by default) to recover from temporary database outages, such as those which occur during a database restart or brief loss of network connectivity. You can affect how c3p0 handles errors in acquiring Connections via the following configurable properties:
acquireRetryAttempts
acquireRetryDelay
breakAfterAcquireFailure
When a c3p0 DataSource attempts and fails to acquire a Connection, it will retry up to acquireRetryAttempts times, with a delay of acquireRetryDelay between each attempt. If all attempts fail, any clients waiting for Connections from the DataSource will see an Exception, indicating that a Connection could not be acquired. Note that clients do not see any Exception until a full round of attempts fail, which may be some time after the initial Connection attempt. If acquireRetryAttempts is set to 0, c3p0 will attempt to acquire new Connections indefinitely, and calls to getConnection() may block indefinitely waiting for a successful acquisition.
Once a full round of acquisition attempts fails, there are two possible policies. By default, the c3p0 DataSource will remain active, and will try again to acquire Connections in response to future requests for Connections. If you set breakAfterAcquireFailure to true, the DataSource will consider itself broken after a failed round of Connection attempts, and future client requests will fail immediately.
Note that if a database restart occurs, a pool may contain previously acquired but now stale Connections. By default, these stale Connections will only be detected and purged lazily, when an application attempts to use them, and sees an Exception. If you wish to avoid application Exceptions, you must adopt a connection testing strategy that is likely to detect stale Connections prior to their delivery to clients. (See "Configuring Connection Testing".) Even with active Connection testing (testConnectionsOnCheckout set to true, or testConnectionsOnCheckin and a short idleConnectionTestPeriod), your application may see occasional Exceptions on database restart, for example if the restart occurs after a Connection to the database has already been checked out.
这些连接池的配置按照hibernate的文档配置没有问题,这段时间使用spring的时候配置的是c3p0的数据库连接池,
按照网上某些网友的介绍的配置,在日志中我没有看到连接池的初始化信息,为此自己研究,发现应该如此配置。
先我把配置写下,希望大家以后在配置的时候,不要再走弯路了
代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- ========================= Start of PERSISTENCE DEFINITIONS ========
================= -->
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
<bean id="nativeJdbcExtractor" class="org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor"/>
<bean id="oracleLobHandle" class="org.springframework.jdbc.support.lob.OracleLobHandler" lazy-init="true">
<property name="nativeJdbcExtractor">
<ref local="nativeJdbcExtractor"/>
</property>
</bean>
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass">
<value>${datasource.driverClassName}</value>
</property>
<property name="jdbcUrl">
<value>${datasource.url}</value>
</property>
<property name="properties">
<props>
<prop key="c3p0.minPoolSize">${hibernate.c3p0.minPoolSize}</prop>
<prop key="hc3p0.maxPoolSize">${hibernate.c3p0.maxPoolSize}</prop>
<prop key="hc3p0.timeout">${hibernate.c3p0.timeout}</prop>
<prop key="c3p0.max_statement">${hibernate.c3p0.max_statement}</prop>
<prop key="c3p0.testConnectionOnCheckout">true</prop>
<prop key="user">${datasource.username}</prop>
<prop key="password">${datasource.password}</prop>
</props>
</property>
</bean>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="lobHandler"><ref local="oracleLobHandle"/></property>
<property name="mappingResources">
<list>
<value>com/cs2c/oa2/pojo/Testfile.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.cglib.use_reflection_optimizer">${hibernate.cglib.use_reflection_optimizer}</prop>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.default_schema">${hibernate.default_schema}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="test" class="com.cs2c.oa2.test.TestHibernate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
</beans>
在配置的时候 cp30的属性的名字必须是 ''driverClass' , 'jdbcUrl', 'user' , 'password' 而 <property name="properties">的名字也必须是“properties”,另外cp30配置文件的属性名也都是诸如:"c3p0.minPoolSize"、"hc3p0.maxPoolSize"等等,
java开源,希望大家也多多open,呵呵。我使用的是 spring1.2.6+hibernate3.1,ok,我觉得这些配置是基础知识,希望大家在今后一定要多看文档,在spring文档中有对dbcp如何配置,好了,不多说了。
自动重连的设置。
Configuring Recovery From Database Outages
c3p0 DataSources are designed (and configured by default) to recover from temporary database outages, such as those which occur during a database restart or brief loss of network connectivity. You can affect how c3p0 handles errors in acquiring Connections via the following configurable properties:
acquireRetryAttempts
acquireRetryDelay
breakAfterAcquireFailure
When a c3p0 DataSource attempts and fails to acquire a Connection, it will retry up to acquireRetryAttempts times, with a delay of acquireRetryDelay between each attempt. If all attempts fail, any clients waiting for Connections from the DataSource will see an Exception, indicating that a Connection could not be acquired. Note that clients do not see any Exception until a full round of attempts fail, which may be some time after the initial Connection attempt. If acquireRetryAttempts is set to 0, c3p0 will attempt to acquire new Connections indefinitely, and calls to getConnection() may block indefinitely waiting for a successful acquisition.
Once a full round of acquisition attempts fails, there are two possible policies. By default, the c3p0 DataSource will remain active, and will try again to acquire Connections in response to future requests for Connections. If you set breakAfterAcquireFailure to true, the DataSource will consider itself broken after a failed round of Connection attempts, and future client requests will fail immediately.
Note that if a database restart occurs, a pool may contain previously acquired but now stale Connections. By default, these stale Connections will only be detected and purged lazily, when an application attempts to use them, and sees an Exception. If you wish to avoid application Exceptions, you must adopt a connection testing strategy that is likely to detect stale Connections prior to their delivery to clients. (See "Configuring Connection Testing".) Even with active Connection testing (testConnectionsOnCheckout set to true, or testConnectionsOnCheckin and a short idleConnectionTestPeriod), your application may see occasional Exceptions on database restart, for example if the restart occurs after a Connection to the database has already been checked out.
发表评论
-
Struts2 xwork中ActionContext和ServletActionContext介绍
2011-03-21 11:26 1432ActionContext(Action上下文) ... -
Struts,Hibernate,Spring经典面试题收藏
2010-12-06 08:44 1320Struts,Hibernate,Spring经 ... -
struts1.2中ActionForm的理解
2010-12-03 14:43 1719初学struts的人我认为首 ... -
struts-config.xml 详解
2010-12-03 12:04 941弄清楚struts-config.xml中各项元素的作用,对于 ... -
struts global-exceptions用法
2010-12-03 11:56 1564在用struts框架写web程序时,有可能会遇到很多异常,如u ... -
<servlet-mapping>元素及其子元素
2010-12-03 11:04 1396<servlet-mapping>元素 ... -
servlet mapping 规则
2010-12-03 10:43 1428servlet mapping有三种<url-patte ... -
常用log4j配置
2010-12-03 09:48 919常用log4j配置 常用log4j配置,一般可以采用两种方 ... -
Log4j简介
2010-12-03 09:47 798在强调可重用组件开发的今天,除了自己从头到尾开发一个可重用 ... -
log4j配置祥解
2010-12-03 09:46 980第一步:加入log4j-1.2.8.j ... -
数据库连接池DBCP
2010-12-02 14:54 1054概念:数据库连接池负责分配、管理和释放数据库连接,它允许应用程 ... -
Hibernate持久化对象三种状态的区分,以及save,update,saveOrUpdate,merge,persist等的使用
2010-11-12 20:22 1568Hibernate的对象有3种状态,分别为:瞬时态(Trans ... -
Hibernate持久化对象
2010-11-12 20:20 1220一,持久化对象: 1,置于session管理下的对象叫做持久化 ... -
hibernate核心类简介
2010-11-12 20:16 1161Hibernate Hibernate是一 ... -
J2EE是什么语言
2010-11-11 12:42 5986****** 版权声明 ******** * 在完整保留 ... -
Hibernate最基础的示例
2010-11-04 15:06 1453有关Spring的知识大部分都已经温习完毕,今天开始转向H ... -
struts+spring+hibernate是怎样的架构?
2010-11-01 17:21 1085struts+spring+hibernate是怎 ... -
快速整合struts+spring+hibernate
2010-11-01 17:17 969说明: 使用平台:Eclipse3.2、MyEclipse5 ... -
Spring整合Hibernate
2010-11-01 15:34 1167Spring整合Hibernate的价值在于Spring为Hi ... -
一些有用的网址
2010-11-01 15:10 1002http://wenku.baidu.com/view/7ab ...
相关推荐
struts2+spring+hibernate 配置文件struts2+spring+hibernate 配置文件
这个"jsp+Spring+hibernate"博客系统展示了如何利用现代Java技术栈构建一个功能完善的Web应用。通过结合JSP的视图呈现、Spring的控制层管理和Hibernate的数据持久化,开发者能够快速、高效地开发出具有复杂业务逻辑...
综上所述,"gwt+spring+hibernate"的整合旨在展示如何在Java Web应用中同时利用GWT的富客户端特性、Spring的架构优势和Hibernate的数据持久化能力。通过这样的整合,开发者可以构建出用户体验良好、业务逻辑清晰且...
在这个视频教程中,你可能将学习到如何配置Spring的XML上下文文件以启用注解驱动的配置,如何在Spring MVC中创建注解式的控制器并处理HTTP请求,以及如何通过Hibernate的注解来设计数据模型并执行CRUD操作。...
Spring MVC、Spring 和 Hibernate 是Java Web开发中的三大主流框架,它们各司其职,共同构建了一个强大而灵活的后端架构。Spring MVC 负责处理HTTP请求并将其路由到相应的控制器,Spring 提供了依赖注入(DI)和面向...
标题中的"idea工具创建的Spring+SpringMVC+Hibernate+maven项目"指的是使用IntelliJ IDEA这个集成开发环境(IDE)构建的一个Java Web项目,该项目整合了四个关键的技术框架:Spring、SpringMVC、Hibernate以及Maven...
在这个项目中,"struts+spring+hibernate(mysql)用户登录及文件上传",开发者整合了这三个框架,并结合MySQL数据库实现了一个完整的用户管理系统,包括用户身份验证和文件上传功能。 首先,Struts是MVC(Model-View...
Flex+Spring+Hibernate 整合是企业级应用开发中常见的一种技术栈组合,它结合了Flex前端的富互联网应用程序(RIA)开发能力、Spring框架的依赖注入和事务管理功能,以及Hibernate持久化框架的数据库操作便捷性。...
《图书管理系统spring+struts+hibernate》是一款基于Java技术栈开发的图书管理软件,其核心框架包括Spring、Struts和Hibernate。该系统利用MySQL作为数据库存储数据,提供了完整的数据库备份,确保了数据的安全性与...
总结来说,"struts2+spring+hibernate配置"涉及到了Java Web开发中的三层架构,包括前端控制、业务逻辑和数据持久化。开发者需要理解这三个框架的核心原理,并掌握它们的配置和整合方法,以构建高效、可维护的Web...
在JSF+Spring+Hibernate的组合中,Hibernate作为数据访问层,负责将Java对象映射到数据库中的表,处理SQL查询和更新操作。开发者可以通过配置Hibernate的实体类和映射文件,实现数据的CRUD(创建、读取、更新、删除...
例如,struts.xml中配置Action类及其结果视图,applicationContext.xml中配置Spring Bean,而hibernate.cfg.xml则定义了数据库连接和实体类映射。 在本项目中,"说明.txt"文件可能包含了详细的步骤指导,包括如何...
在IT行业中,构建大型、模块化的Java应用时,通常会采用一些成熟的框架组合,例如Spring、Spring MVC和Hibernate。这些框架协同工作,可以提供强大的后端功能,包括依赖注入、模型-视图-控制器(MVC)架构以及对象...
在本视频教程“Spring MVC + Spring + Hibernate 全注解整合开发视频教程 04”中,我们将深入探讨Java企业级开发中的三大核心技术——Spring、Spring MVC和Hibernate的集成与应用,尤其是通过注解实现的简化配置。...
标题 "Spring+Hibernate+Proxool连接池" 涉及到的是在Java Web开发中,如何使用Spring框架集成Hibernate ORM框架,并结合Proxool作为数据库连接池的技术实践。这通常是为了提高应用性能,有效管理和复用数据库连接,...
12.6.16 编写Spring和Hibernate的配置文件spring-config.xml 12.6.17 编写web.xml 12.6.18 验证示例 12.7 小结 第四篇 J2EE项目案例精选 第十三章 网上调查系统 13.1 系统概述 13.2 需求分析 13.2.1 系统用例图 ...
4. **配置Hibernate**:创建Hibernate的配置文件(通常是hibernate.cfg.xml),配置JDBC连接、数据库方言、缓存策略等。 5. **配置RichFaces**:在faces-config.xml中注册RichFaces扩展,设置所需的组件库和行为。 6...
《ZK+Spring+Hibernate整合详解》 ZK、Spring和Hibernate是Java开发中的三大重要框架,它们分别在用户界面、依赖注入与事务管理、持久层操作方面发挥着关键作用。将这三者进行整合,可以构建出高效、稳定且易于维护...
【标题】"java+Spring+Hibernate整合的企业OA源码"所代表的是一个使用Java编程语言,结合Spring框架和Hibernate持久层框架实现的企业级办公自动化(Office Automation,简称OA)系统的源代码。这样的系统通常用于...
"spring+hibernate和spring+myBatis实现连接多个数据库,同时操作的项目"是针对这种需求的一个解决方案,旨在提供一种灵活且动态的数据源切换机制。 首先,Spring框架作为Java领域中最受欢迎的应用框架之一,其强大...