读书人

SSH调整步骤说明

发布时间: 2012-10-27 10:42:26 作者: rapoo

SSH整合步骤说明
首先交代一下环境:spring 3.0.5 hibernate 3.6.4 struts2.2.1 myeclipse9

简单的步骤内容不做说明了。

第一步下载SSH框架包

Spring:http://www.springsource.org/

Hibernate:http://www.hibernate.org/

Struts2:http://struts.apache.org/2.2.1/index.html

第二部新建一个web 工程

点击web工程

add Spring Capabilities

add struts2 Capabilities

add Hibernate Capabilities

通过myeclipse加入框架,只是为了生成对应的配置文件。 还有就是为了方便后面的开发。不要用myeclipse自带的jar包。不然Jar包冲突就搞死人了。

第三部加入spring hibernate struts2的jar包到lib目录下。

SSH我整理的Jar包我会上传一份附件。由于附件大小限制我去掉了hibernate3.jar
和spring 下所有jar包 你可以自行添加

但是由于自己经验有限 可能有一些jar是你项目用不到的。但起码没有jar包冲突。

sping 目录下dist所有jar包



hibernate jar 包

hibernate3.jar 以及lib/required/所有jar 不要用hibernate自带的cglib-2.2.jar 跟spring会有jar包冲突

单独下载cglib-nodep-2.2 jar

第四步开始写配置文件

注意新版本的xml 命名空间别弄错了。配置文件不要照抄。配置文件目录结构很重要。我的配置文件放置位置不是默认的。

web.xml

<?xml version="1.0" encoding="UTF-8"?><web-app version="3.0" 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_3_0.xsd"><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class><init-param><param-name>config</param-name><param-value>struts-default.xml,com/daqi/modts/configs/struts/struts.xml</param-value></init-param></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>*.action</url-pattern></filter-mapping><filter-mapping><filter-name>struts2</filter-name><url-pattern>*.jsp</url-pattern></filter-mapping><!-- 用于初始化Spring容器的Listener --><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><!-- 配置spring配置文件的路径 --><param-name>contextConfigLocation</param-name><param-value>classpath:com/daqi/modts/configs/spring/*-context.xml</param-value></context-param><!--  <listener><listener-class>org.springframework.web.util.Log4jConfigListener</listener-class></listener><context-param><param-name>log4jConfigLocation</param-name><param-value>classpath:configure/configs/log4j.properties</param-value></context-param><resource-ref><res-ref-name>jdbc/net_hos</res-ref-name><res-type>javax.sql.DataSource</res-type><res-auth>Container</res-auth></resource-ref>--><welcome-file-list><welcome-file>login.jsp</welcome-file></welcome-file-list><!-- <error-page><error-code>500</error-code><location>/other/error.html</location></error-page><error-page><error-code>404</error-code><location>/other/error1.html</location></error-page> --></web-app> 

spring配置文件

<?xml version="1.0" encoding="UTF-8"?><beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:p="http://www.springframework.org/schema/p"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"><!-- 加载DataBase properties<bean id="propertyConfigurer"destroy-method="close">       <!-- 指定连接数据库的驱动 -->       <property name="driverClass" value="com.mysql.jdbc.Driver"/>       <!-- 指定连接数据库的URL -->       <property name="jdbcUrl" value="jdbc:mysql://192.168.1.252:3306/modts?autoReconnect=true&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8"/>       <!-- 指定连接数据库的用户名 -->       <property name="user" value="MODTS"/>       <!-- 指定连接数据库的密码 -->       <property name="password" value="MODTS"/>       <!-- 指定连接数据库连接池的最大连接数 -->       <property name="maxPoolSize" value="20"/>       <!-- 指定连接数据库连接池的最小连接数 -->       <property name="minPoolSize" value="1"/>       <!-- 指定连接数据库连接池的初始化连接数 -->       <property name="initialPoolSize" value="1"/>       <!-- 指定连接数据库连接池的连接的最大空闲时间 -->       <property name="maxIdleTime" value="20"/>    </bean><!-- Hibernate --><bean id="sessionFactory"lazy-init="false"><property name="dataSource"><ref local="dataSource" /></property><property name="mappingDirectoryLocations"><list><value>classpath:com/daqi/modts/model</value></list></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.show_sql">true</prop><prop key="hibernate.format_sql">false</prop>  <prop key="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</prop>        <prop key="hibernate.cache.use_query_cache">false</prop>        <prop key="hibernate.cache.use_second_level_cache">false</prop></props></property></bean> <!-- TransactionManager --><bean id="transactionManager"/></property></bean><!-- 事务拦截器 --> <bean id="baseTransactionProxy"/></property><!--    下面定义事务传播属性--> <property name="transactionAttributes"><props><prop key="find*">PROPAGATION_REQUIRED,readOnly</prop><prop key="add*">PROPAGATION_REQUIRED</prop><prop key="modify*">PROPAGATION_REQUIRED</prop><prop key="remove*">PROPAGATION_REQUIRED</prop><prop key="do*">PROPAGATION_REQUIRED</prop></props></property></bean> <!-- 事务实例动态代理 --> <bean id="autoProxyCreator"/></property></bean><bean id="jdbcTemplate"/></property></bean></beans>


struts.xml

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"><struts><include file="struts-default.xml" /><package name="loginManage"  extends="struts-default"><action name="LoginAction" method="loginUser"><result name="success">indextemp.jsp</result><result name="fail">login.jsp</result></action><action name="LogOutAction" method="loginOut"><result name="success">/login.jsp</result></action><!-- ajax检测id唯一性 --><action name="checkUniqueId" method="checkUniqueId"></action></package><package name="studentsManage" extends="struts-default" namespace="/studentsManage"><action name="studentsInfoBrowse" method="studentsInfoBrowse"><result name="success">/studentsManage/studentsBrowse.jsp</result></action><action name="studentsAddAction" type="redirectAction"><param name="actionName">studentsInfoBrowse</param><param name="namespace">/studentsManage</param></result></action><package><!-- spring管理Struts2 Action --><constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory" /><constant name="struts.ui.theme" value="simple"></constant><constant name="struts.ui.templateDir" value="template"></constant><!-- <constant name="devMode" value="false"></constant>--></struts> 

读书人网 >软件架构设计

热点推荐