SSH整合学习笔记
现在将之前的spring与hibernate整合修改一下,使用C3P0数据库连接池。基本的配置没有改变,只是增加了一个jdbc.properties文件和修改了applicationContext.xml和hibernate.cfg.xml文件的相关配置。
jdbc.properties
jdbcUrl= jdbc:mysql:///spring2hibernate
driverClass = com.mysql.jdbc.Driver
username = root
password =root
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd ">
<context:property-placeholder location="classpath:jdbc.properties" />
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="dataSource">
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${username}"></property>
<property name="password" value="${password}"></property>
<!-- 其他配置 -->
<property name="initialPoolSize" value="3"></property>
<property name="maxPoolSize" value="5"></property>
<property name="minPoolSize" value="3"></property>
<property name="acquireIncrement" value="2"></property>
<property name="maxStatements" value="8"></property>
<property name="maxStatementsPerConnection" value="5"></property>
<property name="maxIdleTime" value="20"></property>
</bean>
</property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:advice id="advice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="save*" propagation="REQUIRED" isolation="DEFAULT" read-only="false" />
<tx:method name="*" read-only="true" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="perform" expression="execution(* com.ty.spring2hibernate.service..*.*(..))" />
<aop:advisor advice-ref="advice" pointcut-ref="perform" />
</aop:config>
<bean id="personDao" class="com.ty.spring2hibernate.dao.impl.PersonDaoImpl">
<property name="hibernateTemplate" ref="hibernateTemplate" />
</bean>
<bean id="personService" class="com.ty.spring2hibernate.service.impl.PersonServiceImpl">
<property name="personDao" ref="personDao" />
</bean>
</beans>
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping resource="com/ty/spring2hibernate/domain/Person.hbm.xml" />
</session-factory>
</hibernate-configuration>
只要做了如上所述的修改就完成了使用c3p0数据库连接池的配置。大大的提高的安全性和灵活性。
源码下载地址:
http://download.csdn.net/source/3489150
相关推荐
SSH整合学习笔记之spring与hibernate整合(二)之c3p0 spring与hibernate整合基于XML方式--c3p0数据库连接池的使用。
SSH整合学习笔记之spring与hibernate简单整合的源码---对应我的博客文章 http://blog.csdn.net/wanghantong/article/details/6653482
SSH整合学习笔记之struts2+spring+hibernate+c3p0源码
Java-Spring+Struts+Hibernate-SSH框架整合01-Spring+Hibernate(一步一步的教你敲代码)(博客园,博客名称:Java-Spring+Struts+Hibernate-SSH框架整合01-Spring+Hibernate)
SSH - SpringMVC4 + Spring4 + Hibernate4 + c3p0 + Mysql.zipSSH -
SSH 框架 struts-2.3.34 spring4.3.12 hibernate5.0.12 Tomcat7 jDK7 IDEA
SSH整合jar包-spring5.0+hibernate5.1+struts2.5 使用测试通过的
整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
SSH笔记-Spring简单整合Hibernate的测试。。。。。。。
j2EE网站制作SSH(Spring+Hibernate+Struts2)框架整合必须的85个jar包
struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页struts spring hibernate 登陆 SSH整合分页功能 SSH整合分页
SSH笔记-整合Spring2、Struts2、Hibernate4的完整步骤
SSH(struts2,Hibernate,Spring)整合及测试亲测可用,百分之白亲测可用。
Struts+Spring+Hibernate--SSH整合实例.doc,Struts+Spring+Hibernate--SSH整合实例.doc,Struts+Spring+Hibernate--SSH整合实例.doc
Struts+Spring+Hibernate-SSH整合开发 Struts+Spring+Hibernate-SSH整合开发
ssh整合 struts hibernate spring ssh整合 struts hibernate spring ssh整合 struts hibernate spring
struts spring hibernate 登陆 SSH整合登陆功能struts spring hibernate 登陆 SSH整合登陆功能struts spring hibernate 登陆 SSH整合登陆功能
基于SSH(Struts2、Spring与Hibernate)框架的学生成绩管理系统 (1) 整合Struts2、Spring和Hibernate框架 (2) 实现“登录”功能 (3) 实现“学生信息管理”功能 (4) 实现“学生成绩管理”功能 (5) ...
整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.20 + Spring4.1.6 + Hibernate4.3.9。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...
有关ssh整合的例子,简单的实现登录,注册功能!本实例利用的是struts2+spring+hibernate