Struts2 Spring Hibernate 的简单整合
来源:互联网 发布:c多线程编程 pdf 编辑:程序博客网 时间:2024/05/21 09:26
首先,加载Spring框架,如图:
为了便于以后添加新的应用,这里把spring所有的Jar包都添加了,下一步,要将Spring的配置文件创建在
WEB-INF目录下,或许不理它,到项目中去移动也可以。单击Finish, 对Spring的添加到此结束。
接着我们再添加Hibernate框架,如图:
接着选择将Hibernate的配置文件交给Spring来进行管理,如图:
再为Hibernate创建一个sessionFactory,如图:
接着再选择数据源,
接着是提示你是否建立sessionFactory,因为已经将sessionFactory交给Spring管理了,所以在这里不用创建了
单击Finish,并将Spring中与Hibernate中一样的Jar包全部替换,这样就完成了对Hibernate框架的加载了。
接着再加载struts2框架,这里就不再详细说明了,详情参考Struts2 + Spring 整合简单例子。呵呵~~~
接着就是配置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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/test"></property>
<property name="username" value="root"></property>
<property name="password" value="3348635"></property>
</bean>
<bean id="sessionfactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<!-- 以下是添加的,不是自动生成的 -->
<prop key="hibernate.connection.autocommit">true</prop>
<prop key="hibernate.show_sql">true</prop>
<!--上面是方便我们对程序的调试,和操作 -->
</props>
</property>
</bean>
<!-- 以下是添加的,不是自动生成的 -->
<!-- HibernateTemplate是一个帮助类,它能简化Hibernate Session的编码和处理HibernateExceptions-->
<bean id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionfactory"/>
</property>
</bean>
<!-- 以上是手动添加的内容 -->
</beans>
这里我们要注意添加注释的一段,这些是对我们接下去的程序很有帮助的。
再编写struts.xml 文件,具体代码如下(因现在只是配置三大框架的环境,所以很简单,空空如也):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
</struts>
接着就是最重要的web.xml配置文件了,在Struts2整合Spring的例子已经说明了,这里也不详说了,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
这时,还不能进行编写详细的代码,应该要先测试下这个环境出错了没。部署项目到 tomcat 里,运行没有
出现错误,如出现错误,请详细检查上面每一步的操作是否一致。
到此为止,开发环境三大框架整合的准备工作就完成了。
- Struts2 Spring Hibernate 的简单整合
- struts2 spring hibernate的整合
- struts2+hibernate+spring的整合
- Struts2+Spring+Hibernate的整合
- Struts2+Spring+Hibernate的整合
- 整合开发Struts2,Hibernate,Spring简单框架的搭建详解
- 整合Struts2,Hibernate和Spring的一个简单例子
- struts2+hibernate+spring整合
- struts2 spring hibernate 整合
- Spring struts2 hibernate 整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- Spring、Struts2、Hibernate整合
- Spring + Hibernate + Struts2整合
- struts2+spring+hibernate整合
- struts2+spring+hibernate整合
- Struts2+Hibernate+Spring整合
- 六级词汇天天练(11.12)
- c#中的interface abstract virtual
- IT管理人才必备的十大能力
- Spring 编程式事务和声明式事务(记录日志)
- 通过Chroot机制让服务器安全到底
- Struts2 Spring Hibernate 的简单整合
- 1000 A + B Problem
- c#中的委托
- C#中的委托数组
- 从oracle读出当前用户的所有表名
- 1001 Sum Problem.
- 证明析构函数隐式转换为vitual的finalize方法
- Struts 2.0的Action讲解
- 1002 A + B Problem II