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整合成功