struts 2.1.8 + spring 2.5.5 + hibernate 3.3.2整合实践
第一步:建立好web工程
第二步:配置struts
把以下包放到lib文件夹
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freemarker-2.3.15.jar
ognl-2.7.3.jar
struts2-core-2.1.8.1.jar
在web.xml添加filter
<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>
src目录建立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>
第三步:加入spring
把spring 2.5下的spring.jar和struts下的struts2-spring-plugin-2.1.8.1.jar放到lib
在web.xml加入一些内容
<context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/applicationContext*.xml</param-value></context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener>
新建WEB-INF/application.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:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" 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"></beans>
第四步:加入hibernate
把hibernate3.3下的hibernate.jar和lib\required下的所有jar都放到lib文件夹
加入commons-dbcp.jar,commons-pool.jar,mysql-connector-java-5.0.8-bin.jar
可能还需要slf4j-nop-1.5.2.jar
然后在application.xml加入datasource,sessionFactory其他元素,具体都可以在网络搜索得到。
由于对struts了解不多,暂时还没加入一些数据库的操作。迟点再看看先!