`
luoyu-ds
  • 浏览: 137372 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

JBPM4.4 学习笔记--2

 
阅读更多

       通过上一篇博客,我们把jbpm基本的开发环境搭建好了。接下来我们可以真正去探索jbpm的奥秘了。

       首先新建一个动态的WEB 工程,导入jbpm,struts,hibernate,spring的jar包(jbpm底层需要数据库的支持的,并且支持hibernate,所以我们可以把对jbpm底层的操作转交给hibernate来处理),据我的测试,jbpm4.4对sql server,oracle,支持都挺好的,但mysql好像有那么一点点不友好,也不知道是不是我自己没整对的原因。

     jar包都导入进来以后,首先我们要配置jbpm几个默认的配置文件,如下图所示:

 


       包jbpm4Configure下的几个配置文件,其中后两个spring的配置文件不是必须的,前提是你不使用spring.ehcache.xml是一个缓存的配置文件,也不是必须的,剩下的都是必须的.其中jbpm.cfg.xml是jbpm的主配置文件,我们打开jpbm.cfg.xml看看里面是什么东东,如下图所示:


      我们可以看到,它里面其实是引入了其他的配置文件而已, 这一些都是jbpm默认的也是必须的配置文件。

 

     如果使用了spring,接下来我们还要配置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:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
      	   http://www.springframework.org/schema/tx
      	   http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
      	   http://www.springframework.org/schema/context
      	   http://www.springframework.org/schema/context/spring-context-2.5.xsd
      	   http://www.springframework.org/schema/aop 
      	   http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

        <!-- 引入其他模块配置 -->
        <import resource="applicationContext_jbpm.xml" />
      
     	<!-- HIBERNATE 基础DAO类  -->
      	
        <!-- 配置数据源 -->   
        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        	<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver">
        	</property>
        	<property name="url" value="jdbc:oracle:thin:@localhost:1521:jbpm4test">
        	</property>
        	<property name="username" value="system"></property>
        	<property name="password" value="admin"></property>

        	<!-- 初始连接数目  -->
        	<property name="initialSize" value="1"></property>	

        	<!-- 最大连接数目  -->
        	<property name="maxActive" value="100"></property>	

        	<!-- 最大空闲连接数目  -->
        	<property name="maxIdle" value="2"></property>

        	<!-- 最小空闲连接数目  -->
        	<property name="minIdle" value="1"></property>	
        </bean>

        <!-- HIBERNATE配置 -->
        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        	<property name="dataSource">
        		<ref bean="dataSource"/>
        	</property><!-- 配置数据源 -->

        	<!-- 配置JBPM实体类 -->
 			<property name="mappingLocations">
				<value>classpath*:/org/jbpm/**/*.hbm.xml</value>
			</property>

        	<property name="hibernateProperties">
        		<props>
        			<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        			<prop key="hibernate.show_sql">true</prop>
        			<prop key="hibernate.hbm2ddl.auto">none</prop>
        		</props>
        	</property>
        	<property name="packagesToScan">
        		<list>
        			<value>jbpm4.org.cn.entity</value>
        		</list>
        	</property>
        	<property name="mappingResources">
        		<list>
         			<value>jbpm.repository.hbm.xml</value>
	            	<value>jbpm.execution.hbm.xml</value>  
	            	<value>jbpm.identity.hbm.xml</value>
	            	<value>jbpm.history.hbm.xml</value>
	             	<value>jbpm.task.hbm.xml</value>
         		</list>
        	</property>

	   </bean>

        <!-- 配置事务管理器  --> 
        <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        	<property name="sessionFactory" ref="sessionFactory"/>
        </bean>

		 <!-- 配置JBPM事务的传播特性 -->
	    <tx:advice id="txAdvice" transaction-manager="txManager">
	        <tx:attributes>
	            <tx:method name="add*" propagation="REQUIRED" />  
	            <tx:method name="del*" propagation="REQUIRED" />  
	            <tx:method name="update*" propagation="REQUIRED" />
	            <tx:method name="save*" propagation="REQUIRED" />  
	            <tx:method name="*" read-only="true" />  
	        </tx:attributes>  
	    </tx:advice>

	    <!-- 配置JBPM的类的方法参与事务 -->
	    <aop:config>  
	        <aop:pointcut id="allManagerMethod"
	            expression="execution(* com.wj.dao.impl.ScheduleDAOImpl.*.*(..))" />  
	        <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice" />
	    </aop:config>

	    <!-- 配置自动扫描 -->
		<context:component-scan base-package="jbpm4.org.cn.*"/>

		<!--	配置注解方式管理事务 -->
		<tx:annotation-driven transaction-manager="txManager" />
        <bean id="hibernateDao" class="jbpm4.org.cn.dao.impl.HibernateDaoImpl">
      		<property name="sessionFactory"  ref="sessionFactory" ></property>
      	</bean>
</beans>

      在spring配置文件开头,我们引入另一个配置文件,applicationContext-jbpm.xml,这个文件是配置jbpm的几个重要service,jbpm的一切工作其实都是通过这几个service来间接实现的,这几个service之间的关于也相对复杂。另外必须注意的是,在applicationContext.xml中:hibernate的hibernate.hbm2ddl.auto属性第一次启动服务器之前必须设置为create.这样hibernate才能自动为jbpm创建它需要的18张表。

 

<property name="hibernateProperties">
        		<props>
        			<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
        			<prop key="hibernate.show_sql">true</prop>
        			<prop key="hibernate.hbm2ddl.auto">create</prop>
        		</props>
        	</property>
 

applicationContext-jbpm.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: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-2.5.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">


		<bean id="springHelper" class="org.jbpm.pvm.internal.processengine.SpringHelper"
        	lazy-init="default" autowire="default" dependency-check="default">  
	        <property name="jbpmCfg">
	            <value>jbpm4Configure/jbpm.cfg.xml</value>
	        </property>
    	</bean>
    	<bean id="processEngine" factory-bean="springHelper" factory-method="createProcessEngine" /> 
		<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
		<bean id="executionService" factory-bean="processEngine" factory-method="getExecutionService" />
	    <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
	    <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
	    <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />
	    <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />
</beans>

 

    这里面配置获取这几个service的方法。它们都是通过processEngine来获取的。

     到了这,我们的一个简单的基于jbpm工作流的工程就建起来了,部署到服务器,启动,如果没报错的话,那么就可以继续往下开发了。。

  • 大小: 4.8 KB
  • 大小: 9.6 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics