基于配置文件(xml)的S2S3H3搭建
本次环境选择:JDK1.6+MySQL数据库+C3P0连接池+(struts2,spring3,hibernate3)
首先,创建WEB工程
然后倒入相关jar包(maven项目,在pom.xml中导入坐标)
首先配置web.xml文件
1 ,Spring的监听器
|
<!--spring配置文件的加载的监听 器--> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> |
2,配置Struts2的过滤器
|
<!--3.struts2核心控制器--> <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>/*</url-pattern> </filter-mapping> |
其次:在web.xml中可配置前端编码过滤器,以及hibernate的加载方式
|
<!--CharacterEncodingFilter进行编码过滤--> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
|
<!--2.懒加载 OpenSessionInviewFilter--> <filter> <filter-name>openSessionInViewFilter</filter-name> <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>openSessionInViewFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> |
接下来配置struts2,hibernate,spring的配置文件
struts.xml
|
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts> <constant name="struts.ui.theme" value="simple"/> <constant name="struts.devMode" value="true" /> <constant name="struts.i18n.encoding" value="UTF-8" /> <package name="default" namespace="/" extends="struts-default"> <action name="testAction" method="test" class="cn.dvt.action.TestAvtion"> <result name="success">/WEB-INF/test.jsp</result> </action> </package> </struts> |
hibernate.cfg.xml
|
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="show_sql">true</property> <property name="format_sql">false</property> <property name="hbm2ddl.auto">update</property> <!-- 懒加载,配合web.xml中配置的 openSessionInViewFilter --> <property name="hibernate.enable_lazy_load_no_trans">true</property> <!--hibernate映射文件的校验模式--> <property name="javax.persistence.validation.mode">none</property> <mapping resource="cn/dvt/domain/User.hbm.xml"></mapping> </session-factory> </hibernate-configuration> |
hibernate的po映射文件
xxx.hbm.xml
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="cn.dvt.domain"> <class name="User" table="T_USER"> <id name="id" column="ID"> <generator class="uuid"></generator> </id> <property name="name" column="NAME"></property> <property name="age" column="AGE"></property> </class> </hibernate-mapping> |
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" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <!--1.数据源--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="com.mysql.jdbc.Driver"></property> <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/dvt?characterEncoding=utf8"></property> <property name="user" value="root"></property> <property name="password" value="admin"></property> </bean> <!--2.SessionFactory--> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <!--3.事务管理器--> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!--4.事务通知--> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="save*" propagation="REQUIRED"></tx:method> <tx:method name="update*" propagation="REQUIRED"></tx:method> <tx:method name="delete*" propagation="REQUIRED"></tx:method> <tx:method name="find*" read-only="true"></tx:method> <tx:method name="*" propagation="REQUIRED"></tx:method> </tx:attributes> </tx:advice> <!--5.aop切面--> <aop:config> <aop:pointcut expression="execution(* cn.dvt.service.impl.*.*(..))" id="myPointCut"></aop:pointcut> <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointCut"></aop:advisor> </aop:config> <!--6.DAO--> <bean id="userDao" class="cn.dvt.dao.impl.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <import resource="classpath:spring/applicationContext-action.xml"></import> <import resource="classpath:spring/applicationContext-service.xml"></import> </beans> |
Struts2在Spring配置文件中配置时 , 一定要注意声明“多例”scope = “prototype”
原因:Spring自身为多例,而struts2是多实例的基于filter。
基于配置文件(xml)的S2S3H3搭建的更多相关文章
- Mybatis系列全解(四):全网最全!Mybatis配置文件XML全貌详解
封面:洛小汐 作者:潘潘 做大事和做小事的难度是一样的.两者都会消耗你的时间和精力,所以如果决心做事,就要做大事,要确保你的梦想值得追求,未来的收获可以配得上你的努力. 前言 上一篇文章 <My ...
- Spring AOP基于配置文件的面向方法的切面
Spring AOP基于配置文件的面向方法的切面 Spring AOP根据执行的时间点可以分为around.before和after几种方式. around为方法前后均执行 before为方法前执行 ...
- 基于认证的代理平台搭建配置squid-20130730
基于认证的代理平台搭建配置squid-20130730 功能:通过squid代理实现 (1)基于用户名密码认证的出口ip路由选择 (2)基于client源ip的出口ip路由选择 (3)基于连接本机ip ...
- spring Quartz基于配置文件和注解的实现
这里仅仅是做简单的记录怎样实现. 一.基于配置文件的实现 ①编写须要调度的类 package com.study; import org.springframework.scheduling.anno ...
- Spring(二十):Spring AOP(四):基于配置文件的方式来配置 AOP
基于配置文件的方式来配置 AOP 前边三个章节<Spring(十七):Spring AOP(一):简介>.<Spring(十八):Spring AOP(二):通知(前置.后置.返回. ...
- Spring:基于配置文件的创建对象的各种方式
在Spring3.0之前,Spring主要创建对象的方法是基于配置文件的,即在配置文件中为对象进行注册,并且可以在配置文件当中为对象的字段或者称之为属性值进行赋值,接下来首先介绍基于配置文件的创建对象 ...
- 基于微软hyper-v虚拟化服务器搭建方法和步骤整理
基于Microsoft基础设施私有云计算搭建 摘要:私有云是指组织机构建设的专供自己使用的云平台,它所提供的服务不是供他人使用,而是供自己的内部人员或分支机构使用,不同于公有云,私有云部署在企业内部网 ...
- vue进阶:基于vue-cli创建项目(搭建手脚架)
vue-cli安装.创建项目 基于vue-cli创建的项目进行开发 使用vue-cli图形化界面搭建项目 插件与工具 一.vue-cli简介.安装.创建项目 Vue-cli是基于Vue.js进行快速开 ...
- log4j2配置文件xml详细了解
log4j2配置文件xml详细了解 详细参考:https://www.cnblogs.com/new-life/p/9246143.html log4j 2.x版本不再支持像1.x中的.propert ...
- 从零开始:Mysql基于Amoeba的集群搭建
从零开始:Mysql基于Amoeba的集群搭建 准备环境 1.mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz 2.amoeba-mysql-binary-2.0. ...
随机推荐
- jQueryMobile 网页在UC等游览器上无法正常显示或者是无法自适应设备大小,但在QQ游览器上能正常显示的解决方法
造成jQueryMobile网页在QQ游览器上能正常显示,在UC等游览器上无法正常显示或者是无法自适应设备大小的解决方法: 在<head>标签间添加<meta name=" ...
- Java Service Wrapper简介与使用
在实际开发过程中很多模块需要独立运行,他们并不会以web形式发布,传统的做法是将其压缩为jar包独立运行,这种形式简单易行也比较利于维护,但是一旦服务器重启或出现异常时,程序往往无法自行修复或重启.解 ...
- ecmall中static变量的使用-model模型代码设计
function &m($model_name, $params = array(), $is_new = false) { static $models = array(); $model_ ...
- java替换包含html标签
说明一下,该文档内容抄自开源中国里的谋篇文章,由于抄袭时间过于久远,已经找不到博主了!暂不能说明出处,源码博主看见勿气,皆可联系本人! 我的博客,文章属于个人收藏,以解日后需要之急! package ...
- 启用CentOS6.5 64位安装时自带的MySQL数据库服务器
本人在虚拟机上又安装了一台linux机器,作为MySQL数据库服务器用,在安装时选择了系统自带的MySQL服务器端,以下是启用步骤. 首先开启mysqld服务 #service mysqld star ...
- ASP.NET TextBox 当鼠标点击后清空默认提示文字[转]
前台文本框里添加下面2个事件属性: OnFocus="javascript:if(this.value=='提示文字') {this.value=''}" OnBlur=" ...
- C++学习笔记 知识集锦(二)
1. 命名规范 2. 代码格式 3. QString的判断 4. 对象的判空 5. 隐式接口&显式接口 6. vector&string 7. static 8. const 9. v ...
- vim - mark
Using markshttp://vim.wikia.com/wiki/Using_marks1. There is no visible indication of where marks are ...
- SQLite - TRUNCATE TABLE
https://www.tutorialspoint.com/sqlite/sqlite_truncate_table.htm Unfortunately, no TRUNCATE TABLE in ...
- Redhat 7 或者 CentOS 7 密码破解
1.在如下界面按 e 2.在 linux16 这一行的最后面添加 rd.break,然后按 ctrl + x 进入单用户模式 3.以读写的方式重新挂载 sysroot 4.切换到 sysroot 目录 ...