1.新建一个jbpm工程
2.在src目录下
新建一个helloworld包导入以下五个文件:helloworld.jpdl.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?> <process name="helloworld" xmlns="http://jbpm.org/4.4/jpdl"> <start name="start1" g="66,16,48,48"> <transition name="to 提交申请" to="提交申请" g="-71,-17"/> </start> <end name="end1" g="66,348,48,48"/> <task name="提交申请" g="44,96,92,52" assignee="员工"> <transition name="to 部门经理审批" to="部门经理审批" g="-95,-17"/> </task> <task name="部门经理审批" g="44,180,92,52" assignee="部门经理"> <transition name="to 总经理审批" to="总经理审批" g="-83,-17"/> </task> <task name="总经理审批" g="44,264,92,52" assignee="总经理"> <transition name="to end1" to="end1" g="-47,-17"/> </task> </process>
helloworld.png
jbpm.cfg.xml
<?xml version="1.0" encoding="UTF-8"?> <jbpm-configuration> <import resource="jbpm.default.cfg.xml" /> <import resource="jbpm.businesscalendar.cfg.xml" /> <import resource="jbpm.tx.hibernate.cfg.xml" /> <import resource="jbpm.jpdl.cfg.xml" /> <import resource="jbpm.bpmn.cfg.xml" /> <import resource="jbpm.identity.cfg.xml" /> <!-- Job executor is excluded for running the example test cases. --> <!-- To enable timers and messages in production use, this should be included. --> <!-- <import resource="jbpm.jobexecutor.cfg.xml" /> --> </jbpm-configuration>
jbpm.hibernate.cfg.xml
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql:///jbpm</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">2012081006</property> <property name="hibernate.hbm2ddl.auto">update</property> <property name="hibernate.format_sql">true</property> <mapping resource="jbpm.repository.hbm.xml" /> <mapping resource="jbpm.execution.hbm.xml" /> <mapping resource="jbpm.history.hbm.xml" /> <mapping resource="jbpm.task.hbm.xml" /> <mapping resource="jbpm.identity.hbm.xml" /> </session-factory> </hibernate-configuration>
这里的相关配置信息请自己更改
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=hibernate.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' ### log4j.rootLogger=error, stdout #log4j.logger.org.hibernate=info #log4j.logger.org.hibernate=debug ### log HQL query parser activity #log4j.logger.org.hibernate.hql.ast.AST=debug ### log just the SQL #log4j.logger.org.hibernate.SQL=debug ### log JDBC bind parameters ### #log4j.logger.org.hibernate.type=info #log4j.logger.org.hibernate.type=debug ### log schema export/update ### #log4j.logger.org.hibernate.tool.hbm2ddl=debug ### log HQL parse trees #log4j.logger.org.hibernate.hql=debug ### log cache activity ### #log4j.logger.org.hibernate.cache=debug ### log transaction activity #log4j.logger.org.hibernate.transaction=debug ### log JDBC resource acquisition #log4j.logger.org.hibernate.jdbc=debug ### enable the following line if you want to track down connection ### ### leakages when using DriverManagerConnectionProvider ### #log4j.logger.org.hibernate.connection.DriverManagerConnectionProvider=trace
2.搭建jbpm环境,即导入相应的jar包,在这里就不一一列举出来,如果你想要的话,请评论,并私聊我
3.新建一个包,如hellowordAPI
并在此包下新建一个类,如下
package cn.itcast.oa_hellowordAPI; import java.util.List; import org.jbpm.api.Configuration; import org.jbpm.api.ProcessEngine; import org.jbpm.api.task.Task; import org.junit.Test; public class HelloWord_API { private static ProcessEngine processEngine=new Configuration().setResource("jbpm.cfg.xml").buildProcessEngine(); //建表 @Test //ddl.auto=update public void createSchema() throws Exception{ new org.hibernate.cfg.Configuration()// .configure("jbpm.hibernate.cfg.xml").buildSessionFactory(); } //部署流程定义 @Test public void deployProcessDefinition() throws Exception { processEngine.getRepositoryService().createDeployment()// .addResourceFromClasspath("helloword/helloworld.jpdl.xml").addResourceFromClasspath("helloword/helloworld.png").deploy(); } //启动流程实例 @Test public void startProcessInstance() throws Exception { processEngine.getExecutionService().startProcessInstanceByKey("helloworld"); } //查询我的个人任务列表 @Test public void findMyPersonalTaskList() throws Exception { String userId1="员工"; //String userId2="部门经理"; // String userId3="总经理"; System.out.println("---------"+userId1+"--------"); List<Task> tasks=processEngine.getTaskService().findPersonalTasks(userId1); for(Task task:tasks){ System.out.println(task.getId()+"---"+task.getName()+"-----"+task.getAssignee()); } } //办理任务 @Test public void compeleteTask() throws Exception { String userId="10009"; processEngine.getTaskService().completeTask(userId); } }
运行测试即可
时间: 2024-10-10 13:41:05