Spring3.0.4_Struts2.2.1_Hibernate3.6.0_Stey by Step
原文引用:
http://struts.apache.org/2.0.14/docs/struts-2-spring-2-jpa-ajax.html
1.下载
spring-framework-3.0.4.RELEASE.zip
http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring-framework-3.0.4.RELEASE.zip
spring-framework-2.0.8-with-dependencies.zip
http://downloads.sourceforge.net/project/springframework/springframework-2/2.0.8/spring-framework-2.0.8-with-dependencies.zip?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fspringframework%2Ffiles%2Fspringframework-2%2F2.0.8%2Fspring-framework-2.0.8-with-dependencies.zip%2Fdownload&ts=1287368357&use_mirror=nchc
struts2-2.2.1-lib.zip
http://mirror.bjtu.edu.cn/apache//struts/library/struts2-2.2.1-lib.zip
hibernate-distribution-3.6.0.Final-dist.zip
http://nchc.dl.sourceforge.net/project/hibernate/hibernate3/3.6.0.Final/hibernate-distribution-3.6.0.Final-dist.zip
mysql-connector-java-5.1.13.zip
http://gd.tuwien.ac.at/db/mysql/Downloads/Connector-J/mysql-connector-java-5.1.13.zip
eclipse-jee-helios-SR1-win32.zip
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/helios/SR1/eclipse-jee-helios-SR1-win32.zip&url=http://download.actuatechina.com/eclipse/technology/epp/downloads/release/helios/SR1/eclipse-jee-helios-SR1-win32.zip&mirror_id=385
jdk-6u21-windows-i586.exe 下面的地址需要自己选择自己要的jdk
http://www.oracle.com/technetwork/java/archive-139210.html
apache-tomcat-7.0.2.exe
http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.2-beta/bin/apache-tomcat-7.0.2.exe
slf4j-1.6.1.zip
http://www.slf4j.org/dist/slf4j-1.6.1.zip
2.提取包
从spring-framework-3.0.4.RELEASE.zip中spring-framework-3.0.4.RELEASE\dist提取如下包(里面的所有jar包都要)
(有人说不要这个org.springframework.web.struts-3.0.4.RELEASE.jar,但我测试后,可以用这个)
org.springframework.aop-3.0.4.RELEASE.jar
org.springframework.asm-3.0.4.RELEASE.jar
org.springframework.aspects-3.0.4.RELEASE.jar
org.springframework.beans-3.0.4.RELEASE.jar
org.springframework.context-3.0.4.RELEASE.jar
org.springframework.context.support-3.0.4.RELEASE.jar
org.springframework.core-3.0.4.RELEASE.jar
org.springframework.expression-3.0.4.RELEASE.jar
org.springframework.instrument-3.0.4.RELEASE.jar
org.springframework.instrument.tomcat-3.0.4.RELEASE.jar
org.springframework.jdbc-3.0.4.RELEASE.jar
org.springframework.jms-3.0.4.RELEASE.jar
org.springframework.orm-3.0.4.RELEASE.jar
org.springframework.oxm-3.0.4.RELEASE.jar
org.springframework.test-3.0.4.RELEASE.jar
org.springframework.transaction-3.0.4.RELEASE.jar
org.springframework.web-3.0.4.RELEASE.jar
org.springframework.web.portlet-3.0.4.RELEASE.jar
org.springframework.web.servlet-3.0.4.RELEASE.jar
org.springframework.web.struts-3.0.4.RELEASE.jar
从spring-framework-2.0.8-with-dependencies.zip中spring-framework-2.0.8\lib\log4j提取如下包
log4j-1.2.14.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final提取如下包
hibernate3.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final\lib\required提取如下包(所有包,除了commons-collections-3.1.jar,struts里的版本要高一些)
antlr-2.7.6.jar
dom4j-1.6.1.jar
javassist-3.12.0.GA.jar
jta-1.1.jar
slf4j-api-1.6.1.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final\lib\bytecode\cglib提取如下包
cglib-2.2.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final\lib\optional\ehcache提取如下包
ehcache-1.5.0.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final\lib\jpa提取如下包
hibernate-jpa-2.0-api-1.0.0.Final.jar
从hibernate-distribution-3.6.0.Final-dist.zip中hibernate-distribution-3.6.0.Final\lib\optional\c3p0提取如下包
c3p0-0.9.1.jar
从struts2-2.2.1-lib.zip中struts-2.2.1\lib提取如下包
aopalliance-1.0.jar
commons-collections-3.2.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-logging-1.0.4.jar
freemarker-2.3.16.jar
ognl-3.0.jar
struts2-core-2.2.1.jar
struts2-spring-plugin-2.2.1.jar
xwork-core-2.2.1.jar
从mysql-connector-java-5.1.13.zip中mysql-connector-java-5.1.13提取如下包
mysql-connector-java-5.1.13-bin.jar
从slf4j-1.6.1.zip中mysql-connector-java-5.1.13提取如下包
slf4j-log4j12-1.6.1.jar
把这些包拷贝到一个Spring3.0.4_Struts2.2.1_Hibernate3.6.0-lib文件夹中(这个文件夹自己创建一个,主要用途是临时保存这些包)
3.安装JDK和解压Eclipse文件
4.Eclipse配置Tomcat和JDK
a.启动Eclipse (我用的是Eclipse 3.6 for JEE)
Window-->Preferences-->Server-->Runtime Environments-->Add...-->Apache-->Apache Tomcat v7.0-->Next-->Browse...-->
指向Tomcat 7.0的安装路径-->确定-->Installed JREs...-->Add...-->Standard VM-->Next-->Directory...-->
执行jdk1.6.0_21的文件夹(我的在C:\Program Files\Java\jdk1.6.0_21)-->Finish-->选择jdk1.6.0_21-->OK-->
JRE: jdk1.6.0_21-->Finish-->OK
5.创建第1个例子
a.创建Web项目
点击菜单File-->New-->Other...-->Web-->Dynamic Web Project-->Next-->Project name: Spring3_HelloWorld-->
Target runtime: Apache Tomcat v7.0-->Next-->Next-->Content directory: WebRoot (把WebContent改成WebRoot的原因希望能在MyEclipse配合起来)-->
-->选择Generate web.xml deployment descriptor-->Finish-->
b.配置项目为UTF-8格式打开
右键点击Spring3_HelloWorld-->Properties-->Resource-->Text file encoding 选择Other: UTF-8-->OK
c.配置程序
1)在Spring3_HelloWorld\WebRoot\WEB-INF\lib下,把提取出来的放在Spring3.0.4_Struts2.2.1_Hibernate3.6.0-lib文件夹中的jar包拷贝到这里-->
右键点击Spring3_HelloWorld-->Build Path-->Configure Build Path...-->Libraries-->Add JARs-->选中Spring3_HelloWorld\WebRoot\WEB-INF\lib下所有的Jar包(按住Shift从头选到尾)-->
-->OK-->OK-->
修改Spring3_HelloWorld\WebRoot\WEB-INF下的web.xml
修改成如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="person" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>quickstart</display-name>
<!-- Include this if you are using Hibernate -->
<filter>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<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>
<!-- 以下3项参数与log4j的配置相关 -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>60000</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.util.Log4jConfigListener
</listener-class>
</listener>
<!-- end -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
保存-->
2)右键点击Spring3_HelloWorld\Java Resources: src-->New-->Other...-->General-->File-->Next-->
Enter or select the parent folder: Spring3_HelloWorld/src , File name: struts.xml-->
Finish-->struts.xml修改成如下:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
</struts>
-->保存-->
3)右键点击Spring3_HelloWorld\Java Resources: src-->New-->Other...-->General-->Folder-->Next-->
Enter or select the parent folder: Spring3_HelloWorld/src , Folder name: META-INF-->
Finish-->
右键点击Spring3_HelloWorld\Java Resources: src\META-INF-->New-->Other...-->General-->File-->Next-->
Enter or select the parent folder: Spring3_HelloWorld/src/META-INF , File name: persistence.xml-->
Finish-->
persistence.xml修改成如下:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="punit">
</persistence-unit>
</persistence>
-->保存-->
4)右键点击Spring3_HelloWorld\WebRoot\WEB-INF-->New-->File-->File name: log4j.properties-->
Finish-->struts.xml修改成如下:
# Set root logger level to error
log4j.rootLogger=INFO, Console, File
###### Console appender definition #######
# All outputs currently set to be a ConsoleAppender.
log4j.appender.Console=org.apache.log4j.ConsoleAppender
log4j.appender.Console.layout=org.apache.log4j.PatternLayout
log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{3}] %m%n
#log4j.appender.Console.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
###### File appender definition #######
log4j.appender.File=org.apache.log4j.DailyRollingFileAppender
log4j.appender.File.File=spring.log
log4j.appender.File.Append=false
log4j.appender.File.layout=org.apache.log4j.PatternLayout
log4j.appender.File.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c] %m%n
-->保存-->
来源于网络,回归于网络。
我的邮箱:happy.every.day@126.com QQ:48399956
快乐!
2010年10月19日