SSH(struts+spring+hibernate)常用配置整理

web.xml配置

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1"> <!--配置shiro权限-->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 1.加载spring配置文件-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!--2.配置字符编码的过滤器-->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<!--spring-web包提供的CharacterEncodingFilter只能解决POST的中文乱码问题-->
<!--<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>-->
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!—解决hibernate懒加载session关闭的问题,让session存活到关闭action,根据自己实际需求进行是否需要配置-->
<filter>
<filter-name>openSession</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>openSession</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <!-- 3.配置struts的拦截器-->
<filter>
<filter-name>strut2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter> <filter-mapping>
<filter-name>strut2</filter-name>
<url-pattern>/*</url-pattern>
<!--请求和转发都会被strut2拦截
默认情况下,只有请求会被拦截
-->
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
</web-app>

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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"> <!--加载jdbc属性文件-->
<context:property-placeholder location="classpath:jdbc.properties"/> <!--数据源-->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${driverClass}"></property>
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
</bean> <!--Spring框架用于整合hibernate的工厂bean sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!-- 数据源-->
<property name="dataSource" ref="dataSource"/>
<!-- hibernate的其它配置-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<!—配置数据的方言-->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
</props>
</property> <!-- hibernate映射文件-->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:com/gyf/bos/model</value>
</list>
</property>
</bean> <!--事务管理器:如果在service中使用注解来配置事务,
默认是通过transactionManager的id来查找事物管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!-- 配置hiberante的模版 bean-->
<bean class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!--组件扫描-->
<context:component-scan base-package="com.gyf.bos.*"/> <!--引用注解解析器-->
<!--<context:annotation-config></context:annotation-config>--> <!--开启事务注解-->
<tx:annotation-driven></tx:annotation-driven> <!-- 配置远程服务的代理对象 -->
<bean id="customerSerivce" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<!--注入接口类型-->
<property name="serviceInterface" value="com.gyf.crm.service.CustomerService" />
<!--服务访问路径-->
<property name="serviceUrl" value="http://localhost:8888/crm/remoting/customer" />
</bean> <!--shiroFilter-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"></property>
<property name="loginUrl" value="/login.jsp"></property>
<property name="filterChainDefinitions">
<value>
/userAction_login.action = anon
/validatecode.jsp* = anon
/* = authc
</value>
</property>
</bean> <bean id="BOSRealm" class="com.gyf.bos.web.realm.BOSRealm"></bean> <!--注册缓存管理器-->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!--注入ehcache配置文件-->
<property name="cacheManagerConfigFile" value="classpath:ehcache.xml"></property>
</bean> <!--添加shiro权限管理-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="BOSRealm"></property>
<property name="cacheManager" ref="cacheManager"></property>
</bean> <!--开启shiro注解-->
<!--=======================================================================================-->
<!--1.开启自动代理-->
<!-- <bean id="defaultAdvisorAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
&lt;!&ndash; 强制使用cglib为Action创建代理对象 &ndash;&gt;
<property name="proxyTargetClass" value="true"></property>
</bean> &lt;!&ndash;2.切面类&ndash;&gt;
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor" /> <bean class="com.gyf.bos.web.action.StaffAction" scope="prototype"></bean>-->
<!--=======================================================================================--> <!-- 流程引擎配置对象 -->
<bean id="processEngineConfiguration"
class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"/>
<property name="transactionManager" ref="transactionManager"/>
<property name="databaseSchemaUpdate" value="true" />
</bean> <!-- 使用工厂创建流程引擎对象 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"/>
</bean> <!-- 注册Service -->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"/>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"/>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"/>
<bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService"/> </beans>

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.devMode" value="true"></constant> <package name="p1" extends="struts-default"> <!--配置全局的结果视图-->
<global-results>
<result name="login" type="redirect">/login.jsp</result>
<result name="UnauthorizedUrl" type="redirect">/authorizing.jsp</result>
</global-results> <!--抛出异常来到自定义页面-->
<global-exception-mappings>
<exception-mapping exception="org.apache.shiro.authz.UnauthorizedException" result="UnauthorizedUrl"></exception-mapping>
</global-exception-mappings> <!-- 配置jsp页面的访问规则-->
<action name="page_*_*" >
<result name="success">/WEB-INF/pages/{1}/{2}.jsp</result>
</action> <!--用户模块-->
<action name="userAction_*" class="com.gyf.bos.web.action.UserAction" method="{1}">
<result name="home">/WEB-INF/pages/common/index.jsp</result>
<result name="list">/WEB-INF/pages/admin/userlist.jsp</result>
<result name="loginfailure">/login.jsp</result>
</action> <!--取派员模块-->
<action name="staffAction_*" class="com.gyf.bos.web.action.StaffAction" method="{1}">
<result name="success">/WEB-INF/pages/base/staff.jsp</result> </action> <!--区域模块-->
<action name="regionAction_*" class="com.gyf.bos.web.action.RegionAction" method="{1}">
<result name="success">/WEB-INF/pages/base/region.jsp</result>
</action> <!--分区模块-->
<action name="subareaAction_*" class="com.gyf.bos.web.action.SubareaAction" method="{1}">
<result name="success">/WEB-INF/pages/base/subarea.jsp</result>
</action> <!--定区模块-->
<action name="decidedzoneAction_*" class="com.gyf.bos.web.action.DecidedzoneAction" method="{1}">
<result name="success">/WEB-INF/pages/base/decidedzone.jsp</result>
</action> <!--工单模块-->
<action name="noticebillAction_*" class="com.gyf.bos.web.action.NoticebillAction" method="{1}">
</action> <!--工作单模块-->
<action name="workordermanageAction_*" class="com.gyf.bos.web.action.WorkordermanageAction" method="{1}">
</action> <!--权限模块-->
<action name="functionAction_*" class="com.gyf.bos.web.action.FunctionAction" method="{1}">
<result name="success">/WEB-INF/pages/admin/function.jsp</result>
</action> <!--角色模块-->
<action name="roleAction_*" class="com.gyf.bos.web.action.RoleAction" method="{1}">
<result name="success">/WEB-INF/pages/admin/role.jsp</result>
</action> <!--流程定义模块-->
<action name="processDefinitionAction_*" class="com.gyf.bos.web.action.ProcessDefinitionAction" method="{1}">
<result name="list">/WEB-INF/pages/workflow/processdefinition_list.jsp</result>
<result name="viewpng" type="stream">
<param name="contentType">image/png</param>
<param name="inputName">imgIS</param>
</result>
</action> <!--流程实例模块-->
<action name="processInstanceAction_*" class="com.gyf.bos.web.action.ProcessInstanceAction" method="{1}">
<result name="list">/WEB-INF/pages/workflow/processinstance.jsp</result>
</action>
</package>
</struts>

其他的一些配置文件

log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### direct messages to file hibernate.log ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=E:/bos.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n ### set log levels - for more verbose logging change 'info' to 'debug' ###
# 日志级别【最好配置到error】-输出源
log4j.rootLogger=info , stdout , file

ehcache.xml

<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../config/ehcache.xsd">

    <diskStore path="java.io.tmpdir"/>
<defaultCache
maxElementsInMemory="10000"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="120"
memoryStoreEvictionPolicy="LRU"
/>
</ehcache>
  • maxElementsInMemory :设置基于内存的缓存中可存放的对象最大数目
  • eternal:设置对象是否为永久的,true表示永不过期,此时将忽略
  • timeToIdleSeconds 和 timeToLiveSeconds属性; 默认值是false
  • timeToIdleSeconds:设置对象空闲最长时间,以秒为单位, 超过这个时间,对象过期。当对象过期时,EHCache会把它从缓存中清除。如果此值为0,表示对象可以无限期地处于空闲状态。
  • timeToLiveSeconds:设置对象生存最长时间,超过这个时间,对象过期。如果此值为0,表示对象可以无限期地存在于缓存中. 该属性值必须大于或等于 timeToIdleSeconds 属性值
  • overflowToDisk:设置基于内在的缓存中的对象数目达到上限后,是否把溢出的对象写到基于硬盘的缓存中
  • diskPersistent 当jvm结束时是否持久化对象 true false 默认是false
  • diskExpiryThreadIntervalSeconds 指定专门用于清除过期对象的监听线程的轮询时间
  • memoryStoreEvictionPolicy - 当内存缓存达到最大,有新的element加入的时候, 移除缓存中element的策略。默认是LRU(最近最少使用),可选的有LFU(最不常使用)和FIFO(先进先出)

SSH(struts+spring+hibernate)常用配置整理的更多相关文章

  1. SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别

    SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...

  2. SSH(Struts+spring+hibernate)配置

    1.spring和struts 1)web.xml 配置spring的ContextLoaderListener(监听器) 配置Struts的StrutsPrepareAndExecuteFilter ...

  3. 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓

    hibernate工作原理 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6.提 ...

  4. [转] 浅谈ssh(struts,spring,hibernate三大框架)整合的意义及其精髓

      hibernate工作原理 原理: 1.读取并解析配置文件 2.读取并解析映射信息,创建SessionFactory 3.打开Sesssion 4.创建事务Transation 5.持久化操作 6 ...

  5. SSH:Struts + Spring + Hibernate 轻量级Java EE企业框架

    Java EE(Java Platform,Enterprise Edition)是sun公司(2009年4月20日甲骨文将其收购)推出的企业级应用程序版本.这个版本以前称为 J2EE.能够帮助我们开 ...

  6. SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)之间区别

    http://m.blog.csdn.net/article/details?id=52795914#0-qzone-1-52202-d020d2d2a4e8d1a374a433f596ad1440

  7. 用eclipse搭建SSH(struts+spring+hibernate)框架

    声明: 本文是个人对ssh框架的学习.理解而编辑出来的,可能有不足之处,请大家谅解,但希望能帮助到大家,一起探讨,一起学习! Struts + Spring + Hibernate三者各自的特点都是什 ...

  8. 【SSH进阶之路】Struts + Spring + Hibernate 进阶开端(一)

    [SSH进阶之路]Struts + Spring + Hibernate 进阶开端(一) 标签: hibernatespringstrutsssh开源框架 2014-08-29 07:56 9229人 ...

  9. SSH(Struts2+Spring+Hibernate)框架搭建流程<注解的方式创建Bean>

    此篇讲的是MyEclipse9工具提供的支持搭建自加包有代码也是相同:用户登录与注册的例子,表字段只有name,password. SSH,xml方式搭建文章链接地址:http://www.cnblo ...

随机推荐

  1. Spring原理系列一:Spring Bean的生命周期

    一.前言 在日常开发中,spring极大地简化了我们日常的开发工作.spring为我们管理好bean, 我们拿来就用.但是我们不应该只停留在使用层面,深究spring内部的原理,才能在使用时融汇贯通. ...

  2. ES6 之 Integer数据类型

    1.简介(仅仅是提案) js所有数字都保存成64为浮点数,这就决定了整数的精确程度只能到53个二进制位. 大于这个范围的整数,js是无法精确表示的,这使得js不合适进行科学和金融方面的精确计算. 故引 ...

  3. 设计模式讲解3:ChainOfResponsibility模式源码

    声明:迁移自本人CSDN博客https://blog.csdn.net/u013365635 责任链模式,和普通的函数逐层调用栈形成的逻辑链条不通,责任链会落实到某一个具体实施者完成该责任,而普通函数 ...

  4. Python心得--新手开发注意

    1  注释 介绍 在大多数编程语言当中,注释都是一项非常有用的功能.我们开始编写的程序之中都只包含Python代码,但是随着程序越来越大.越来越复杂,就应在其中添加说明,对你解决问题的方法进行大致的阐 ...

  5. 加速软件源更新和安装 ubuntu 软件中心

    Linux mint 12 修改加速软件源更新和安装 ubuntu 软件中心 由于 linux mint 12 是基于 ubuntu 的,可以使用 ubuntu 的源(Ubuntu 11.10 代号 ...

  6. 题解 P2382 【化学分子式】

    题目 不懂为什么,本蒟蒻用在线算法打就一直炸...... 直到用了"半离线"算法...... 一遍就过了好吗...... 某位机房的小伙伴一遍就过了 另一位机房的小伙伴也是每次都爆 ...

  7. STL——算法

    以下内容大多摘自<C++标准程序库> STL提供了一些标准算法,包括搜寻.排序.拷贝.重新排序.修改.数值运算等.算法并不是容器类别的成员函数,而是一种搭配迭代器使用的全局函数. #inc ...

  8. 利用FastJson,拼接复杂嵌套json数据&&直接从json字符串中(不依赖实体类)解析出键值对

    1.拼接复杂嵌套json FastJson工具包中有两主要的类: JSONObject和JSONArray ,前者表示json对象,后者表示json数组.他们两者都能添加Object类型的对象,但是J ...

  9. 9)用request方式

    一个带有html的代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...

  10. UML-各阶段如何编写用例

    1.前文回顾 用例的根本价值:发现谁是关键参与者,他要实现什么目标? 需求分类,见<进化式需求>:制品,见<初始不是需求阶段>中的表4-1 2.各阶段编写何种用例,均针对下图展 ...