上一篇 Spring2.5 + Struts2 + Hibernate3 整合 [1/2]
1.
修改
spring
的配置文件,配置整合
hibernate
在
/WEB-INF/classes/spring.xml
中加入:
<!--
配置
dataSource -->
<
bean
id
=
"dataSource"
class
=
"org.apache.commons.dbcp.BasicDataSource"
destroy-method
=
"close"
>
<
property
name
=
"driverClassName"
value
=
"com.mysql.jdbc.Driver"
/>
<
property
name
=
"url"
value
=
"jdbc:mysql://localhost:3306/dev?useUnicode=true&characterEncoding=utf-8"
/>
<
property
name
=
"username"
value
=
"root"
/>
<
property
name
=
"password"
value
=
"root"
/>
<!--
连接池启动初始连接数
-->
<
property
name
=
"initialSize"
value
=
"1"
/>
<!--
连接池最大活动连接数
-->
<
property
name
=
"maxActive"
value
=
"50"
/>
<!--
最大空闲值
-->
<
property
name
=
"maxIdle"
value
=
"2"
/>
<!--
最小空闲值
-->
<
property
name
=
"minIdle"
value
=
"1"
/>
</
bean
>
<!--
整合
Hibernate3
的
sessionFactory -->
<
bean
id
=
"sessionFactory"
class
=
"org.springframework.orm.hibernate3.LocalSessionFactoryBean"
>
<
property
name
=
"dataSource"
ref
=
"dataSource"
/>
<
property
name
=
"mappingResources"
>
<
list
>
<
value
>
com/erison/action/Person.hbm.xml
</
value
>
</
list
>
</
property
>
<
property
name
=
"hibernateProperties"
>
<
props
>
<
prop
key
=
"hibernate.dialect"
>
org.hibernate.dialect.MySQL5Dialect
</
prop
>
<
prop
key
=
"hibernate.show_sql"
>
false
</
prop
>
<
prop
key
=
"hibernate.format_sql"
>
false
</
prop
>
</
props
>
</
property
>
</
bean
>
<!--
配置
spring
针对
hibernate
的事务管理器
-->
<
bean
id
=
"txManager"
class
=
"org.springframework.orm.hibernate3.HibernateTransactionManager"
>
<
property
name
=
"sessionFactory"
ref
=
"sessionFactory"
/>
</
bean
>
<!--
配置使用注解的方式来使用事务
-->
<
tx:annotation-driven
transaction-manager
=
"txManager"
/>
|
*
至此,整合
Hibernate3
已经完毕,要想使用还需进行以下步骤。
2.
创建类及测试
1.
创建
DTO
类
com.erison.action.Person
:
package
com.erison.action;
public
class
Person {
private
long
id
;
private
String
name
;
private
int
age
;
public
long
getId() {
return
id
;
}
public
void
setId(
long
id) {
this
.
id
= id;
}
public
String getName() {
return
name
;
}
public
void
setName(String name) {
this
.
name
= name;
}
public
int
getAge() {
return
age
;
}
public
void
setAge(
int
age) {
this
.
age
= age;
}
}
|
2.
创建
DB
类
com.erison.action.DBPerson
:
package
com.erison.action;
import
org.hibernate.SessionFactory;
import
org.springframework.orm.hibernate3.HibernateTemplate;
import
org.springframework.transaction.annotation.Propagation;
import
org.springframework.transaction.annotation.Transactional;
public
class
DBPerson {
HibernateTemplate
template
=
null
;
public
void
setSessionFactory(SessionFactory sessionFactory) {
template
=
new
HibernateTemplate(sessionFactory);
}
@Transactional
(propagation=Propagation.
REQUIRED
)
public
void
insert(Person person) {
template
.save(person);
template
.get(DBPerson.
class
, 1);
}
@Transactional
(readOnly=
true
)
public
Person find(
long
|
分享到:
相关推荐
struts2+spring2.5+hibernate3.2整合完整项目,带数据库脚本 ,mysql,tomcat,myeclipse完整工程
Spring2.5+Hibernate3.3+Struts1.3整合需要用到的所有jar文件
Spring2.5+Struts1.3.8+Hibernate3.0整合详细配置 希望对初学者有所帮助
struts2.0+spring2.5+hibernate3.0整合框架,下载导入到eclipse下即可。。启动tomcat前先修改jdbc.properties文件。由于lib文件较大,所以请自行导入相关lib包。
这是一个spring2.5+struts2+hibernate3.3的整合完整项目,struts2的ActionBean,hibernate的sessionFactory交与了spring容器创建与管理
NULL 博文链接:https://ilyon.iteye.com/blog/725910
这是一个完整的Spring2.5+Struts2.3+hibernate3.6整合实现登陆的实例,使用的数据库是Mysql,大家下下来还需要导入servlet-api.jar。
jbpm4整合struts2+spring2.5+hibernate3.3.doc
整合S2SH+Freemarker,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
利用ssh(Spring2.5+Struts2.1+Hibernate3.3)全注解整合这3个流行的框架,实现了增、删、改、查,分页,的功能。
struts2+spring2.5+hibernate3.2 找了半天没看到。自己整了一个。
Struts2+Spring2.5+hibernate3.3整合 Struts2+Spring2.5+hibernate3.3整合
整合S2SH+Freemarker+oscache,后台用Spring管理各个bean,Hibernate做数据库持久化,viewer用Freemarker。整合中对Struts2,Hibernate,Spring都采用Annotation进行注解类。
Eclipse中Struts2+Spring2.5+Hibernate3整合,由于包超过上传限制,所以把lib里面的包给分成两个下载点,等下附上
Dwr2+Struts2+Spring2.5+Hibernate3完美整合--用户登录注册系统
struts2+spring2.5+hibernate3整合经典实例 开发环境: MyEclispe 5.1 数据库:mysql5
SSH整合jar包-spring5.0+hibernate5.1+struts2.5 使用测试通过的
以Struts2+Spring2.5+Hibernate3开发的网上购物系统,文件里面有数据库Oracle 10g,导入即可使用
NULL 博文链接:https://gaobo424.iteye.com/blog/870162
struts2+spring2.5+hibernate3整合的完整示例,数据库为Oracle Database 10g Express Edition