Spring3.0、Hibernate3.0、Struts2整合文件配置
来源:互联网 发布:mac版的flashplayer 编辑:程序博客网 时间:2024/05/11 20:30
一、导入Spring3.0、Hibernate3.0、Struts2开发库。
二、配置web.xml文件的内容,如下:
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> <display-name></display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <listener> <description>Spring core configuration</description> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>*.action</url-pattern> </filter-mapping></web-app>
1.如上struts2的核心控制器filter也可配置为如下类
org.apache.struts2.dispatcher.FilterDispatcher
2.FilterDispatcher和StrutsPrepareAndExecuteFilter、StrutsPrepareFilter、
ExecuteFilter的区别参见:
http://peng-hao1988.iteye.com/admin/blogs/1472063
三、Spring的配置文件applicationContext.xml的配置内容如下:
<?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"><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/myssh"></property><property name="username" value="root"></property><property name="password" value="123"></property></bean><bean id="sessionFactory"class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"><!-- if use the hibernate.cfg.xml as dataSource configuration, cancel the annotations --><!-- remove other properties and dataSource bean. --><!-- <property name="configLocation" value="classpath:hibernate.cfg.xml" /> --><property name="dataSource"><ref bean="dataSource" /></property><property name="hibernateProperties"><props><prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop><prop key="hibernate.hbm2ddl.auto">update</prop></props></property><property name="mappingResources"><list><value>com/hzboy/orm/Userinfo.hbm.xml</value></list></property></bean><bean id="userAct" class="com.hzboy.action.UserManagerAct" scope="prototype"><property name="userService" ref="userService"></property></bean><bean id="userService" class="com.hzboy.service.UserManagerService"><property name="dao" ref="dao"></property></bean><bean id="dao" class="com.hzboy.dao.BaseDao"><property name="sessionFactory" ref="sessionFactory"/></bean></beans>
1.Demo默认Hibernate的DataSource、HibernateProperties、
MappingResources信息配置到applicationContext.xml文件中。
如果使用Hibernate.cfg.xml配置这些信息,需要在
applicationContext.xml文件中将configLocation这个属性去
掉注释,将其他的property注释或删除。
2.applicationContext.xml默认放在webRoot\WEB-INF\路径下,
如果想要将spring的配置文件移动到其他文件夹或修改名字,需要在
web.xml中添加如下代码:
<context-param> <description>我的spring配置文件放在WEB-INF根目录下,文件名为springconfig.xml</description> <param-name>contextConfigLoaction</param-name> <param-value>/WEB-INF/springconfig.xml</param-value></context-param>
3.Demo默认Hibernate的DataSource、HibernateProperties、
MappingResources信息配置到applicationContext.xml文件
中。如果使用Hibernate.cfg.xml配置这些信息,需要在
applicationContext.xml文件中将configLocation这个属性
去掉注释,并将其他的property注释或删除。
Hibernate.cfg.xml配置如下:
<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><!-- Generated by MyEclipse Hibernate Tools. --><hibernate-configuration><session-factory><property name="hbm2ddl.auto">update</property><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.url">jdbc:mysql://localhost:3306/myssh</property><property name="connection.username">root</property><property name="connection.password">123</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="myeclipse.connection.profile">MySQL</property><mapping resource="com/hzboy/orm/Userinfo.hbm.xml" /></session-factory></hibernate-configuration>
四、配置struts2的配置文件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><constant name="struts.objectFactory" value="spring" /><package name="myApp" extends="struts-default"><global-results><result name="error">/WEB-INF/jsp/error.jsp</result><result name="success">/WEB-INF/jsp/success.jsp</result></global-results><action name="userManagerAct" class="userAct" method="doLogin"><result name="login">/index.jsp</result></action><action name="query" class="userAct" method="doQuery" /><action name="delete" class="userAct" method="doDelete" /><action name="edit" class="userAct" method="doEdit"><result name="editUser">/WEB-INF/jsp/editUser.jsp</result></action><action name="add" class="userAct" method="doAdd"><result name="addUser">/WEB-INF/jsp/addUser.jsp</result></action></package></struts>
1.当使用spring管理struts2的 action时要注意需在struts2的action配
置文件中添加如下代码:
<constant name="struts.objectFactory" value="spring" />
并且需要将struts2-spring-plugin-2.2.1.jar添加到classpath中去。
2.如要将Struts2的默认配置文件struts.xml文件重命名或移动到WEB-INF
到下去,需要在web.xml的struts2过滤器中添加如下代码:
<init-param> <description>我的struts配置文件放在WEB-INF根目录下,文件名为action.xml</description> <param-name>config</param-name> <param-value>struts-default.xml,struts-plugin.xml,../action.xml</param-value></init-param>
五、基本配置已经弄完了,在用工具添加MyEclipse和Eclipse添加开发库是要注意
,尽量使用高版本的,如果是工具自带的库,一般不会出现问题,如果有错误的话,一
般是JAR包冲突,把一些名字一样版本号不一样的包删除低版本的。如果是用户自定义
的开发库最好不要随意添加JAR包,去官方下载完整的开发库,根据需要添加,如果是
在不知道那些是需要的,那就全部添加进去。
- Spring3.0、Hibernate3.0、Struts2整合文件配置
- struts2.1.8+Spring3.0+Hibernate3.3整合+Hibernate二级缓存配置
- 整合Struts2.1+Hibernate3.3+Spring3.0
- spring3.0 + hibernate3.5 + struts2的整合
- 毕业设计(二)---struts2 hibernate3 spring3.0 整合
- Struts2.2+Spring3.0+Hibernate3.6整合
- struts2+Spring3+hibernate3.3整合配置
- struts2+Spring3+hibernate3.3整合配置
- struts2 spring3 hibernate3整合
- Struts2+Spring3+Hibernate3整合
- Struts2+Hibernate3+Spring3 整合
- Struts2+Spring3+Hibernate3整合
- spring3 struts2 hibernate3整合
- struts2+hibernate3.0+spring3.0整合所需包
- Struts2.0+Hibernate3.0+Spring3.2整合实例
- SSH整合(struts2.2.1 + spring3.0 + hibernate3.3)
- struts2.1.8+spring3.0+hibernate3.3整合开发问题
- spring3.0+hibernate3.6+struts2.2.3整合过程
- DBMS_ROWID包的使用(查询rowid资料 )!
- 关闭窗口自动执行代码/周期调用函数【学习笔记】
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- DevExpress GridControl 控件常见问题
- 运动目标检测、阴影检测及目标跟踪中用得到的标准测试视频下载(大量IBM提供视频)
- Spring3.0、Hibernate3.0、Struts2整合文件配置
- pkg-config的使用 详解
- Ajax处理JSON数据参考【学习笔记】
- vb 创建文本文件 有换行符问题
- 类的this指针
- 战斗系统的伪原创工具
- yum 源设置
- 任务一:自定义combobox
- jboss性能优化