在{project}/src/test下有一个osworkflow-spring-hibernate-loader.xml文件,这是针对osworkflow,spring,hibernate3集成的spring配置文件,但是其中各项定义还是使用的com.opensymphony.workflow.spi.hibernate包中的类(想不明白)。下面着手更改了。
1.dataSource
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName"> <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value> </property> <property name="url"> <value>jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=PDM_ORG</value> </property> <property name="username"><value>sa</value></property> <property name="password"><value>xx</value></property> </bean> |
这是针对mssqlserver2000的配置。
2.sessionFactory
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop> <prop key="hibernate.show_sql">true</prop> <prop key="hibernate.hbm2ddl.auto">create-update</prop> <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> </props> </property> <property name="mappingResources"> <list> <value>com/opensymphony/workflow/spi/hibernate3/WorkflowDescriptor.hbm.xml</value> <value>com/opensymphony/workflow/spi/hibernate3/HibernateCurrentStep.hbm.xml</value> <value>com/opensymphony/workflow/spi/hibernate3/HibernateHistoryStep.hbm.xml</value> <value>com/opensymphony/workflow/spi/hibernate3/HibernateWorkflowEntry.hbm.xml</value> <value>com/opensymphony/module/propertyset/hibernate/PropertySetItemImpl.hbm.xml</value> </list> </property> </bean> |
其实WorkflowDescriptor.hbm.xml、HibernateCurrentStep.hbm.xml、HibernateHistoryStep.hbm.xml、HibernateWorkflowEntry.hbm.xml这四个文件在hibernate,hibernate3中都有,而且都是hibernate这个包中四个类的mapping文件。
WorkflowDescriptor.hbm.xml这个文件是loader包中各个descriptor的mapping文件,在OSworkflow-3.0-dev这个版本中加入了将工作流定义持久化到数据库中。
3.transactionManager
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" > <ref local="sessionFactory"/> </property> </bean> |
4.transactionInterceptor
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager"><ref local="transactionManager"/></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> |
5.OSworkflow持久化方式定义
<bean id="workflowStore" class="com.opensymphony.workflow.spi.hibernate3.SpringHibernateWorkflowStore"> <property name="sessionFactory"><ref local="sessionFactory"/></property> <property name="propertySetDelegate"> <bean id="propertySetDelegate" class="com.opensymphony.workflow.util.PropertySetDelegateImpl"/> </property> </bean> |
6.workflowFactory定义
<bean id="workflowFactory" class="com.opensymphony.workflow.spi.hibernate3.SpringHibernateWorkflowFactory" init-method="initDone"> <property name="sessionFactory"><ref bean="sessionFactory"/></property> <property name="reload"><value>true</value></property> <property name="validate"><value>false</value></property> </bean> |
这里需要说明的是在原文件中的定义是SpringHibernateWorkflowFactory是从AbstractWorkflowFactory继承,看了源码其中并没有“resource”这个属性,并且只有XMLWorkflowFactory才有“resource”这个属性,代表从该属性定义的资源中读取工作流的定义文件。如果是要从xml文件中读取工作流定义时要将工厂类改为com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory,但是如果要从数据库中读取工作流的定义只有将工厂类定义为com.opensymphony.workflow.spi.hibernate3.SpringHibernateWorkflowFactory才可以。
从xml文件读取定义:
<bean id="workflowFactory" class="com.opensymphony.workflow.spi.hibernate.SpringWorkflowFactory" init-method="init"> <property name="sessionFactory"><ref bean="sessionFactory"/></property> <property name="resource"><value>workflows.xml</value></property> <property name="reload"><value>true</value></property> </bean> |
7. osworkflowConfiguration
<bean id="osworkflowConfiguration" class="com.opensymphony.workflow.config.SpringConfiguration"> <property name="store"><ref local="workflowStore"/></property> <property name="factory"><ref local="workflowFactory"/></property> </bean> |