spring+hibernate:整合

步骤1:引入类包

如下图:这里是所有的类包,为后面的struts整合考虑

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAPcAAAJkCAIAAABCgyDAAAAgAElEQVR4nO2dS+s9yVnHz0vIW8gL8AUIceOqmf1sAgpGBDELFzZkIS6UZBYiuMnmD73RhRckk9G5mMGYToK6ipssQnYdEJ0QLyQgCDGmXZzT3VX1XKr6WlVPfz8Mw/l3V1dVn99z6lR3P59Tj3EN77zzzieffE/67+23315VGwDX8JhfvffX70dLv/POO8peBDook0e8iIMe5SMCHRTJkWP5OI5v3rz5whe+8His+/DI9O2j6Qa9zNA1jydtHxzrQuqZ9wd7hq6JNwpqYvtY/u1vf/uvvvrhn/zZV/7y3Y8++Ojjb37zm+M4fvLJ9968ebMvyt3ITojyvnsV6NswztkqnyCU78T2sbzvv/GP//yjf//Pn/7bj3/6h3/6rb//+tef27/zne9cGuX8gZEdq+oFtbN9LO+/8Xe/9Pl/+NJX//UP/uZffvuPP/z444+f25UoX+YQrzG3bx9N17XOxMGZZrS9E419+2jathFH63Ech65ZFeRTu6TGpTzb4Ug3QHlsH8s//trffuY3v/7pz33r137rK7/6++999NFHz+0JY7kbu1PALPMNdizvW2Zm7TJ0jRB6zLjdt4+m6YJ2lQPSuwFKZMVY/tYXv+L+9/7773/m8x9//ktf+4Vf/+A3fu/NBx988CymRfkyNi4jNBfQ6kbuanPVnNzfRj8ezl6tw6AawrFc+f+nfvl33f/efffd//qPH/33//zfz/73pz/5yY/fe++9Zz1ilC/hNM8tNkW5UjEDe2AQ5cLIHekwqIZ18/Jf+fPPuf/97Gc/++53v/v973//5z//+Q9/+MNnGTHK5whZ7m8cEeXChOS5idxKee3y5kfhTGl6EekwqIZ18/LHF99y/+v7/s2bN1/+8pd/8IMfzGXkGcs01WjaVhvLp2kCufrkwmuZvjiTGCY8J7xd/t1y2pbeYVANK8byf/qdX6T/0WK77yRmp29xC8UWK8byDz/76e/90Vvufx9+9tO0WPVRjvHaHCv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OAL7wBUC9oErBOwDVwjYB64QsE+lrlCWe7nbZBznSWew35CMUzgZXaE95IjyTTIOQrkEMrpCe8j7XE7K72O6ZOgBYsVc5go5Y1r/El+YNKaha5zEPJpFxOk80rPCEtYSmk6Vr3Q5hMtkq0nGKZwLXaFX9o8jFUw5gk3TzMlvc3Jswro/5a8l1LePpun6oH35EO/Tiy+Bo7jQFRr9kXeJ6Kbrn6+nTdEVUZ7R48ZxoWsJCXnzdO8ymFeZ2lo417pC3vziGdPPYXPomrafZwJJUf5oGjlBtaC1hNwoNyvjFM6VrpA/Y3n+SZ25Stu27sgWW/dH94QKWUvIadV7ZU3GKZx1Ub7DFVr+gNwrEpaRdX98jUVM8pauPoXQPGMtoeVAxUWqXsYpnBu6QuVgR8YpnDUWhRFXqBgwXl/FDV2hAjAn4xTOunCEKwRqBOEI7IMoB/b5f+WO9TOjXqOcAAAAAElFTkSuQmCC" alt="" />

步骤2:修改web.xml

在web.xml中加入下面的配置

  <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>//这个beans.xml是在src目录下建立的文件,具体下面会陈述
</context-param>
<!-- 对Spring容器进行实例化 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <filter>
<filter-name>OpenSessionInViewFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>OpenSessionInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

步骤3:建立实体类并建立hibernate的配置文件

package com.test.model;

public class user {
private int id;
private String username;
private String password;
private String age; public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public void setUsername(String username) {
this.username = username;
}
public String getUsername() {
return username;
}
public void setId(int id) {
this.id = id;
}
public int getId() {
return id;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.test.model">
<class name="user" table="[User]">
<cache usage="read-write" region="com.test.model.user"/>
<id name="id">
<generator class="identity"/>
</id>
<property name="username" column="username" not-null="true"/>
<property name="password" column="password" not-null="true"/>
<property name="age" column="age" not-null="false"/>
</class>
</hibernate-mapping>

步骤4:建立beans.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:annotation-config/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url" value="jdbc:sqlserver://127.0.0.1:1433;databaseName=Hibernate"/> ////数据库链接
<property name="username" value="sa"/>
<property name="password" value="123456"/>
<!-- 连接池启动时的初始值 -->
<property name="initialSize" value="1"/>
<!-- 连接池的最大值 -->
<property name="maxActive" value="500"/>
<!-- 最大空闲值.当经过一个高峰时间后,连接池可以慢慢将已经用不到的连接慢慢释放一部分,一直减少到maxIdle为止 -->
<property name="maxIdle" value="2"/>
<!-- 最小空闲值.当空闲的连接数少于阀值时,连接池就会预申请去一些连接,以免洪峰来时来不及申请 -->
<property name="minIdle" value="1"/>
</bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/test/model/user.hbm.xml</value> //////这个是实体类的hibernate配置文件
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:annotation-driven transaction-manager="txManager"/> <bean id="userService" class="com.test.implement.userServiceBean"/> ///// </beans>

步骤5:定义一个userService接口,并实现它。

package com.test.Interface;

import java.util.List;

import com.test.model.user;

public interface userService {

    public    List<user> getAll();

}
package com.test.implement;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.transaction.annotation.Transactional; import com.test.Interface.userService;
import com.test.model.user; public class userServiceBean implements userService{ @Resource private SessionFactory sessionFactory; @Transactional
public List<user> getAll() { return sessionFactory.getCurrentSession().createQuery("from user").list(); } }

步骤6:单元测试

package com.test.test;

import java.util.List;

import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.test.Interface.userService;
import com.test.model.user; import junit.framework.TestCase; public class userTest { private static userService userservice; @BeforeClass
public static void setUpBeforeClass() throws Exception {
ApplicationContext ac=new ClassPathXmlApplicationContext("beans.xml");
userservice=(userService) ac.getBean("userService");
} @Test
public void testGetAll()
{
List<user> users=userservice.getAll();
for (user item : users) {
System.out.print("Id:"+item.getId()+"\t");
System.out.print("username:"+item.getUsername()+"\t");
}
} }

错误1:

org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

原因:在实现的地方,没有加入事务

解决办法:在对应方法上面加@Transactional

到此,spring和hibernate整合成功

spring+hibernate+struts整合(1)的更多相关文章

  1. spring+hibernate+struts整合(2)

    spring和struts2的整合 1:配置Web.xml文件 <filter> <filter-name>struts2</filter-name> <fi ...

  2. jbpm与spring hibernate struts整合

    applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xm ...

  3. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  4. Struts+Spring+Hibernate项目整合AJAX+JSON

    1.什么是AJAX AJAX是 "Asynchronous JavaScript and XML" 的简称,即异步的JavaScript和XML. 所谓异步,就是提交一个请求不必等 ...

  5. Spring与Struts整合

    Spring框架是一个非常优秀的轻量级Java EE容器,Spring框架是整个轻量级Java EE框架的核心.大部分的Java EE应用,都会考虑使用Spring容器管理应用中的组件,从而保证各组件 ...

  6. spring 和 struts 整合遇到的问题(学习中)

    一大早就报错 org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.eng ...

  7. spring和struts整合

    整合准备:导入jar包 如果只是访问action,没有做数据库方面的操作的话 只需要导入下面的jar spring相关jar 以及struts相关jar包 整合过程: 用到了struts所以需要在we ...

  8. Spring,hibernate,struts的面试笔试题(含答案)

    Hibernate工作原理及为什么要用? 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久 ...

  9. Struts2 Spring Hibernate 框架整合 Annotation MavenProject

    项目结构目录 pom.xml       添加和管理jar包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

随机推荐

  1. tomcat server获取用户的请求地址

    当用户 与 tomcat之间 用 nginx做跳转时, HttpServletRequest 中的 getRemoteHost()方法获取到的只是nginx的地址,而不能拿到用户真正的请求地址 解决方 ...

  2. (转)UML常用图的几种关系的总结

    在UML的类图中,常见的有以下几种关系: 泛化(Generalization),  实现(Realization), 关联(Association), 聚合(Aggregation), 组合(Comp ...

  3. UVA 11426 GCD - Extreme (II) (欧拉函数+筛法)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=70017#problem/O 题意是给你n,求所有gcd(i , j)的和,其中 ...

  4. HDU 5441 Travel (并查集+数学+计数)

    题意:给你一个带权的无向图,然后q(q≤5000)次询问,问有多少对城市(城市对(u,v)与(v,u)算不同的城市对,而且u≠v)之间的边的长度不超过d(如果城市u到城市v途经城市w, 那么需要城市u ...

  5. MVC神韵---你想在哪解脱!(十四)

    修正票价字段的精度 前面我们追加数据的时候遗留下来一个问题,就是在追加数据的时候,票价(Price)字段中输入的是9.99元,但是电影清单显示画面中该数据的票价字段显示为10元,这是为什么?这个问题发 ...

  6. EasyUI datetimebox设置默认值为当前时间

    设置value="${notices.release_time}" <input class="easyui-validatebox easyui-datetime ...

  7. C++的辅助工具介绍

    1 文档类  (1) Doxygen  参考站点:http://www.doxygen.org  Doxygen是一种适合C风格语言(如C++.C.IDL.Java甚至包括C#和PHP)的.开放源码的 ...

  8. VC中监测函数运行时间(一)—分钟,秒,毫秒

    //myTimer.h // [10/16/2013 Duan Yihao] #pragma once #include "StdAfx.h" ////////////////// ...

  9. arcgis下载

    你懂的~ t.cn/RA4cc3k 密码ygdr 包含10.2全部,含有(亲测)字样表示测试过OK的,SP是从esri网站下载的几乎全部patch和sp,包括desktop.engine和sever: ...

  10. Web项目的三层架构和MVC架构异同

    http://www.cnblogs.com/zhhh/archive/2011/06/10/2077519.html 又看到有人在问三层架构和MVC的关系,感觉这种问题有点教条化了.因为它们都在逻辑 ...