spring2.5.4+hibernate3.2.6+struts2+jbpm3.2.2
本文转至:http://blog.csdn.net/gabriel80/article/details/2472237#967954
1.首先我们要介绍
web.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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>xj</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/log4j.properties</param-value>
</context-param>
<!-- Spring XML 文件读入 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:/applicationContext-resources.xml
classpath:/applicationContext-dao.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<!-- Spring框架中对请求的编码方式进行统一管理 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!-- 配置Struts2框架的核心Filter -->
<filter>
<filter-name>struts</filter-name>
<!-- 配置Struts 2核心Filter的实现类 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Struts 2的核心FilterDispatcher拦截所有用户请求 -->
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<!-- 启动Spring Listener contextConfigLocation -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 防止内存泄露 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Listener log4jConfigLocation -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
2.然后我们介绍
applicationContext_resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- For mail settings and future properties files -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
<value>classpath:mail.properties</value>
</list>
</property>
</bean>
<!-- 配置数据源 使用Apache DBCP 连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${sqlserver.driverClassName}" />
<property name="url" value="${sqlserver.url}" />
<property name="username" value="${sqlserver.username}" />
<property name="password" value="${sqlserver.password}" />
<property name="maxActive" value="100"/>
<property name="maxWait" value="1000"/>
<property name="poolPreparedStatements" value="true"/>
<property name="defaultAutoCommit" value="true"/>
</bean>
</beans>
然后这个文件就要使用到辅助文件jdbc.properties:
sqlserver.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver
sqlserver.url=jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=AOP_JBPM;SelectMethod=cursor;
sqlserver.username=sa
sqlserver.password=sa
sqlserver.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
mysql.driverClassName=com.mysql.jdbc.Driver
mysql.url=jdbc:mysql://localhost/itsm?createDatabaseIfNotExist=true&useUnicode=true&characterEncoding=utf-8
mysql.username=root
mysql.password=
mysql.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
3.介绍applicationContext-dao.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Hibernate SessionFactory -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="typeDefinitions" ref="jbpmTypes"/>
<!-- 导入用户自定义的*.hbm.xml文件 -->
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/com/dhcc/itsm/</value>
</list>
</property>
<!--
throw error:
cvc-complex-type.2.3: Element 'list' cannot have character [children],
because the type's content type is element-only.
<property name="mappingJarLocations">
<list>
<value>WEB-INF/lib/jbpm-jpdl.jar</value>
<value>WEB-INF/lib/jbpm-identity.jar</value>
</list>
</property>
-->
<!-- 可以导入包里的所有文件。但是此写法不适用WEBLOGIC -->
<property name="mappingLocations">
<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</prop>
<!--
为了使HIBERNATE3查询的时候使用正确的语法需要指明查询工厂类,如果不指定回出现
ClassNotFoundException: org.hibernate.hql.ast.HqlToken 的错误!
<prop key="hibernate.query.factory_class">org.hibernate.hql.ast.ASTQueryTranslatorFactory</prop>
-->
<!--
Hibernate3.0 采用新的基于ANTLR的HQL/SQL查询翻译器,
在Hibernate的配置文件中,hibernate.query.factory_class
属性用来选择查询翻译器。
(1)选择Hibernate3.0的查询翻译器:
hibernate.query.factory_class=
org.hibernate.hql.ast.ASTQueryTranslatorFactory
(2)选择Hibernate2.1的查询翻译器hibernate.query.factory_class=
org.hibernate.hql.classic.ClassicQueryTranslatorFactory
-->
</props>
</property>
</bean>
<!-- JPBM的大字段处理类型 -->
<bean id="jbpmTypes" class="org.springframework.orm.hibernate3.TypeDefinitionBean">
<property name="typeName" value="string_max" />
<property name="typeClass" value="org.jbpm.db.hibernate.StringMax" />
</bean>
<!-- 定义processdefinition.xml是否自动发布 -->
<bean id="processDefinitionFactoryBean"
class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
<property name="definitionLocation"
value="classpath:com/dhcc/itsm/jbpm/process/simple/processdefinition.xml" />
</bean>
<!-- 配置spring-modules-jbpm31.jar中提供的JbpmConfiguration -->
<bean id="jbpmConfiguration"
class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
<property name="sessionFactory" ref="sessionFactory" />
<property name="configuration" value="classpath:jbpm.cfg.xml" />
<property name="createSchema" value="false" />
<!-- 定义processdefinition.xml是否自动发布 -->
<property name="processDefinitions">
<list>
<ref local="processDefinitionFactoryBean" />
</list>
</property>
</bean>
<bean id="jbpmTemplate"
class="org.springmodules.workflow.jbpm31.JbpmTemplate">
<constructor-arg index="0" ref="jbpmConfiguration" />
</bean>
<!-- 使用BeanNameAutoProxyCreator的代理方法 -->
<!--
<bean id="myTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactoryForJbpm" />
</bean>
<bean id="beanNameProxy"
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Manager</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionManager">
<ref bean="myTransactionManager" />
</property>
<property name="transactionAttributes">
<props>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
-->
<!-- TransactionManager 自动创建代理,使用时必须获取实现类,工厂创建代理可以添加所要继承的接口 -->
<bean id="transactionProxyFactoryBean"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="singleton">
<value>false</value>
</property>
<property name="interceptorNames">
<list>
<value>transactionInterceptor</value>
</list>
</property>
</bean>
<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<property name="transactionAttributes">
<props>
<prop key="find*">
PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
</prop>
<prop key="*">
PROPAGATION_REQUIRED,ISOLATION_DEFAULT,-Exception
</prop>
</props>
</property>
<property name="transactionManager">
<ref bean="hibernateTransactionManager" />
</property>
</bean>
<!-- TransactionManager spring拦截器中的事务管理 -->
<bean id="hibernateTransactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
</beans>
4.最后就是用到用户自定义的applicationContext.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- 自定义类 -->
<bean id="serviceTemplate" parent="transactionProxyFactoryBean">
<property name="target">
<bean class="com.。。。.service.ServiceTemplate">
<property name="jbpmManage" ref="jbpmManage" />
</bean>
</property>
</bean>
<!-- Add new Managers here -->
<bean id="jbpmManage" class="com.。。。。.manage.JbpmManage">
<property name="jbpmDao">
<ref bean="jbpmDao" />
</property>
</bean>
<!-- Add new DAOs here -->
<bean id="jbpmDao" class="com.。。。。.dao.JbpmDao">
<property name="jbpmTemplate">
<ref bean="jbpmTemplate" />
</property>
</bean>
<!-- Add new Actions here -->
<bean id="deployProcessDefinition" class="com.。。。.actions.DeployProcessDefinition">
<property name="serviceTemplate" ref="serviceTemplate" />
</bean>
<bean id="startProcess" class="com.。。。。.actions.StartProcess">
<property name="serviceTemplate" ref="serviceTemplate" />
</bean>
<bean id="itsmMemu" class="com.。。。actions.ItsmMemu">
<property name="serviceTemplate" ref="serviceTemplate" />
</bean>
<bean id="processInstanceMemu" class="com.。。。.actions.ProcessInstanceMemu">
<property name="serviceTemplate" ref="serviceTemplate" />
</bean>
<!-- 事务通知 -->
<!--
<tx:advice id="txAdvice" transaction-manager="hibernateTransactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true"/>
<tx:method name="*" propagation="REQUIRES_NEW" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
-->
<!-- aop代理设置 -->
<!--
<aop:config proxy-target-class="true">
<aop:pointcut id="txPointcut" expression="execution(* com...*Service.*(..))"/>
<aop:pointcut id="logPointcut" expression="execution(* com.r..*Service.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut" order="1"/>
<aop:aspect id="logAspect" ref="logInterceptor" order="2" >
<aop:after-throwing
pointcut-ref="logPointcut"
method="serviceIntercept" />
</aop:aspect>
</aop:config>
-->
</beans>
5.介绍JBPM的配置信息jbpm.cfg.xml:在这里我们应该注意我们用到的是SPRING .所以我就没有用HIBRENATE来产生sessionFactory。。
<jbpm-configuration>
<!--
The default configurations can be found in org/jbpm/default.jbpm.cfg.xml
Those configurations can be overwritten by putting this file called
jbpm.cfg.xml on the root of the classpath and put in the customized values.
-->
<jbpm-context>
<service name="tx" factory="org.jbpm.tx.TxServiceFactory" />
<!--
<service name="persistence">
<factory>
<bean class="org.jbpm.persistence.db.DbPersistenceServiceFactory">
<field name="isTransactionEnabled">
<false />
</field>
<field name="isCurrentSessionEnabled">
<true/>
</field>
</bean>
</factory>
</service>
-->
<service name="persistence" factory="org.jbpm.persistence.db.DbPersistenceServiceFactory" />
<service name="message" factory="org.jbpm.msg.db.DbMessageServiceFactory" />
<service name="scheduler" factory="org.jbpm.scheduler.db.DbSchedulerServiceFactory" />
<service name="logging" factory="org.jbpm.logging.db.DbLoggingServiceFactory" />
<service name="authentication" factory="org.jbpm.security.authentication.DefaultAuthenticationServiceFactory" />
</jbpm-context>
<--<string name="resource.hibernate.cfg.xml" value="hibernate.cfg.xml" />-->
<!-- configuration resource files pointing to default configuration files in jbpm-{version}.jar -->
<string name="resource.business.calendar" value="org/jbpm/calendar/jbpm.business.calendar.properties" />
<string name="resource.default.modules" value="org/jbpm/graph/def/jbpm.default.modules.properties" />
<string name="resource.converter" value="org/jbpm/db/hibernate/jbpm.converter.properties" />
<string name="resource.action.types" value="org/jbpm/graph/action/action.types.xml" />
<string name="resource.node.types" value="org/jbpm/graph/node/node.types.xml" />
<string name="resource.parsers" value="org/jbpm/jpdl/par/jbpm.parsers.xml" />
<string name="resource.varmapping" value="org/jbpm/context/exe/jbpm.varmapping.xml" />
<string name="resource.mail.templates" value="jbpm.mail.templates.xml" />
<long name="jbpm.msg.wait.timout" value="5000" singleton="true" /> <!-- 5 seconds -->
<int name="jbpm.byte.block.size" value="1024" singleton="true" />
<bean name="jbpm.task.instance.factory" class="org.jbpm.taskmgmt.impl.DefaultTaskInstanceFactoryImpl" singleton="true" />
<bean name="jbpm.variable.resolver" class="org.jbpm.jpdl.el.impl.JbpmVariableResolver" singleton="true" />
<string name="jbpm.mail.smtp.host" value="localhost" />
<bean name="jbpm.mail.address.resolver" class="org.jbpm.identity.mail.IdentityAddressResolver" singleton="true" />
<bean name="jbpm.job.executor" class="org.jbpm.job.executor.JobExecutor">
<field name="jbpmConfiguration"><ref bean="jbpmConfiguration" /></field>
<field name="name"><string value="JbpmJobExector" /></field>
<field name="nbrOfThreads"><int value="1" /></field>
<field name="idleInterval"><int value="5000" /></field>
<field name="maxIdleInterval"><int value="3600000" /></field>
<field name="historyMaxSize"><int value="20" /></field>
<field name="maxLockTime"><int value="600000" /></field>
<field name="lockMonitorInterval"><int value="60000" /></field>
<field name="lockBufferTime"><int value="5000" /></field>
</bean>
</jbpm-configuration>
6.hibernate.cfg.xml文件。。我置空。。
<hibernate-configuration>
<session-factory>
</session-factory>
</hibernate-configuration>
7.介绍struts2的配置文件struts.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="false"/>
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="html"/>
<constant name="struts.objectFactory" value="spring"/>
<constant name="struts.custom.i18n.resources" value="ApplicationResources,errors"/>
<constant name="struts.multipart.maxSize" value="2097152"/>
<constant name="struts.ui.theme" value="css_xhtml"/>
<constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/"/>
<constant name="struts.enable.SlashesInActionNames" value="true"/>
<include file="struts_itsm.xml" />
<!-- Add packages here -->
</struts>
8.然后会用到struts_itsm.xml文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<!-- package提供了将多个Action组织为一个模块的方式
package的名字必须是唯一的 package可以扩展 当一个package扩展自
另一个package时该package会在本身配置的基础上加入扩展的package
的配置 父package必须在子package前配置
name:package名称
extends:继承的父package名称
abstract:设置package的属性为抽象的 抽象的package不能定义action 值true:false
namespace:定义package命名空间 该命名空间影响到url的地址,例如此命名空间为/test那么访问是的地址为http://localhost:8080/struts2/test/XX.action
-->
<package name="itsm" extends="struts-default">
<action name="ItsmMemu" class="com.。。。.actions.ItsmMemu">
<result>/itsm/ItsmMemu.jsp</result>
</action>
<action name="*" class="com.。。。.actions.ItsmMemu">
<result>/itsm/{1}.jsp</result>
</action>
<action name="ChooseProcessDefinition" class="com.。。。.actions.ChooseProcessDefinition">
<result>/itsm/ChooseProcessDefinition.jsp</result>
</action>
<action name="DeployProcessDefinition" class="com.。。。.actions.DeployProcessDefinition">
<result name="input">/itsm/Missing.jsp</result>
<result name="success" type="redirect-action">ItsmMemu</result>
</action>
<action name="ProcessInstanceMemu" class="com.。。。.actions.ProcessInstanceMemu">
<result>/itsm/ProcessInstanceMemu.jsp</result>
</action>
<action name="StartProcess" class="com。。。.actions.StartProcess">
<result>/itsm/StartProcess.jsp</result>
</action>
<action name="NextProcess" class="com.。。。.actions.NextProcess">
<result>/itsm/NextProcess.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
当然首页INDEX.JSP就不重复了啊
9.当然如果用到上诉框架。肯定是不能缺少一些JAR包的。
这样就可以把上诉框架配置完毕。。
有什么不周的地方。。请大家多提建议。。。