JBPM 和 Spring 的结合

JBPM 和 Spring 的结合
2008-10-11 21:34

第一步:将JBPM的配置写入HIbernate,生成相应的表
     * 拷贝相关的依赖包到WEB-INF/lib下面(bsh.jar/ jcr-1.0.jar/ jbpm-identity.jar/ jbpm-jpdl.jar)
   * 修改hibernate.cfg.xml,添加JBPM的映射配置,以及缓存属性的配置

 

        <property name="mappingLocations">
            <value>classpath*:/org/jbpm/**/*.hbm.xml</value>
        </property>

 

第二步:与Spring集成
   * 集成JBPM与spring,需要用到第三方的集成包:spring-modules-0.8.zip
   * 将其中的spring-modules-jbpm31.jar拷贝到WEB-INF/lib下面即可
   * 集成JBPM与Spring的方法是:将JbpmConfiguration对象的创建交给Spring来完成
   * 所以,需要在spring配置文件中配置JbpmConfiguration对象的创建
    <!-- 配置JbmpConfiguration -->
    <bean id="jbpmConfiguration" class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
     <property name="configuration" value="classpath:jbpm.cfg.xml"></property>
    </bean>
   * 这时候,需要jbpm.cfg.xml,这是JBPM的配置文件,我们可以从:
    JBPM_HOME\src\jpdl\org\jbpm目录下拷贝default.jbpm.cfg.xml文件,
    并重新命名为jbpm.cfg.xml


第三步:如何实现业务逻辑类

   * 用到jbpmConfiguration对象的时候,需要注入 (<property name="jbpmConfiguration" ref="jbpmConfiguration"></property>)
   * 当我们使用JbpmContext对象来操纵JBPM的时候,需要将JbpmContext的HibernateSession对象设置为当前的HibernateSession对象
   private JbpmContext getContext(){
     JbpmContext context = jbpmConfiguration.createJbpmContext();
     context.setSession(getSession());
     return context;
    }

 

    <!-- JBPM Hibernate SessionFactory -->
    <bean id="jbpmSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>

        <property name="mappingLocations">
        	<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
        </property>
    </bean>

    <bean id="jbpmConfiguration"
    	class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
    	<property name="configuration" value="classpath:jbpm.cfg.xml"></property>
    	<property name="sessionFactory" ref="jbpmSessionFactory" />
    	<property name="processDefinitions">
    		<list>
    			<ref local="qingjia" />
    		</list>
    	</property>
    	<property name="createSchema" value="false" />
    	
    </bean>

    <bean id="qingjia" class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean">
        <property name="definitionLocation" value="file:${oa_application.config}/qingjia/processdefinition.xml"/>
    </bean>

 

 

附:

        	<!-- jbpm 3.2.6 -->
        <property name="mappingLocations">
        	<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
        </property>
        <property name="typeDefinitions">
        	<ref bean="jbpmTypes" />
        </property>


    <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>

 

<!-- jbpm 3.2.6.sp1 -->
    <import resource="file:${oa_application.config}/cn/firstsoft/firstframe/plugins/jbpm/applicationContext-jbpm.xml"/>

 

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans default-autowire="byName">
	<!-- JBPM 3.2.6.SP1 -->
	<bean id="jbpmConfiguration"
		class="org.springmodules.workflow.jbpm31.LocalJbpmConfigurationFactoryBean">
		<property name="sessionFactory" ref="sessionFactory" />
		<property name="configuration"
			value="file:${oa_application.config}/conf/jbpm.cfg.xml" />
		<!--
		<property name="createSchema" value="false"/>
		-->
		<!-- unused, it can be deploy false, deploy success, then set it -->
		<!--
			<property name="processDefinitions"> <list> <ref
			local="testProcess"/> </list> </property>
		-->
	</bean>
	<bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate">
		<property name="jbpmConfiguration" ref="jbpmConfiguration" />
	</bean>

	<!-- 动态分配任务的处理,利用node-enter事件 
	<bean id="jbpmProcessDao" class="cn.firstsoft.firstframe.plugins.jbpm.JbpmProcessDao">
		<property name="template" ref="jbpmTemplate" />
	</bean>

	<bean id="nodeEnterActionHandler" parent="baseTxService">
		<property name="target">
			<bean
				class="cn.firstsoft.modules.workflow.service.handler.NodeEnterActionHandler" />
		</property>
	</bean>
	<bean id="endNodeEnterActionHandler" parent="baseTxService">
		<property name="target">
			<bean
				class="cn.firstsoft.modules.workflow.service.handler.EndNodeEnterActionHandler" />
		</property>
	</bean>
	<bean id="taskEndCountersignActionHandler" parent="baseTxService">
		<property name="target">
			<bean
				class="cn.firstsoft.modules.workflow.service.handler.TaskEndCountersignActionHandler" />
		</property>
	</bean>	
	-->
</beans>

 

你可能感兴趣的:(spring,bean,Hibernate,workflow,jbpm)