工作流工程整合spring的Web项目流程操作之关键分析、整合spring与web交互发布实现
?
?
????? 之前的博文中有讲到怎么单独的配置工作流工程。现在就接着说如何将工作流程图与Web整合。在整合Web首先就
来与Spring进行整合。
????? 整合spring有一下些操作步骤:
?1.复制整合包spring-modules-jbpm31.jar
?2.把Action三大接口类配置在spring的applicationContext.xml
??? 如:
<!-- action 动作接口-->
?<bean id="endAction"???? ref="sessionFactory"></property>
????? <property name="configuration"? value="classpath:org/jbpm/default.jbpm.cfg.xml"></property>
?</bean>
//org/jbpm/default.jbpm.cfg.xml? 为jbpm.cfg.xml 文件中的
?4.把jbpm设计图关联图中的动作、事件类全部改为代理JbpmHandlerProxy
?在。org.springmodules.workflow.jbpm31.JbpmHandlerProxy
?
?? 类型改为bean,注入配置文件类和aciton类
//下面的这两个属性需要在配置文件(processdefinition.xml)中代码中手动添加
?? <factoryKey>jbpmConfig</factoryKey>
?? <targetBean>bossAction</targetBean>
如:<start-state name="开始">
??<transition name="" to="写报销单"></transition>
??<event type="node-leave">
???<action name="开始" config-type="bean">
??????????? <factoryKey>jbpmConfig</factoryKey>
??????????? <targetBean>startAction</targetBean>
???????? </action>
??</event>
?</start-state>
//jbpmConfig :步骤3中所配置的 id值???? startAction:步骤1中所对应的动作接口 id值
?5.把测试类继承为JbpmDaoSupport类
?? 并把测试类在applicationContext.xml中配置bean
如:<!-- 测试类 -->
?<bean id="jbpmTest" ref="jbpmConfig"></property>
?</bean>
6.测试
?? 测试类在整合spring之后与web的关联操作。
如下:
? //读取配置文件
?private JbpmConfiguration getConfig(){
??return super.getJbpmConfiguration();
?}
?//读取上下文件
?private JbpmContext getContext(){
??JbpmContext context = getConfig().getCurrentJbpmContext();
??if (context==null)
???context = getConfig().createJbpmContext();
??return context;
?}
?//建表
?private void createTable(){
??getConfig().createSchema();
?}
?
?//发布
?private void deployProcessionDefintion(){
??ProcessDefinition? pd = ProcessDefinition.parseXmlResource("simple/processdefinition.xml");
??pd.setName("s09报销单");
??getContext().deployProcessDefinition(pd);
??getContext().close();
?}
?//开启流程实例
?private void createInstance(String pname,String name){
?? ProcessDefinition pd = getContext().getGraphSession().findLatestProcessDefinition("s09报销单");
?? ProcessInstance?? pi = pd.createProcessInstance();
?? pi.getContextInstance().setVariable("start", name);
?? pi.signal();
?? getContext().close();
?}
?//写报销单
?private void writer(String name,float money,String msg){
?? Session? session = getContext().getSession();
?? String?? hql???? = "from TaskInstance where ACTORID_=? and END_ is null";
?? Query??? query?? = session.createQuery(hql);
?? query.setParameter(0, name);
??
??? List<TaskInstance> list =query.list();// getContext().getTaskList(name);
??? //System.out.println(list.size());
??? if (list!=null)
???? for (TaskInstance ti : list) {
????if (ti.getName().equals("写报销单")){
????? //System.out.println("进来了没有");
????? ti.setVariable("money", money);
????? ti.setVariable("msg", msg);
????? ti.end();
?????
????? break;
????}
????
???}
??? getContext().close();?
?}
?// 领导审批
?private void agree(int tid,boolean agree){
???? TaskInstance ti = getContext().getTaskInstance(tid);
???? if (ti!=null){
???? ?String old = (String) ti.getVariable("status");
???? ?if (agree)
???? ?{
???? ??ti.setVariable("status", old+"(同意)");
???? ??ti.end("同意");
???? ?}
???? ?else{
???? ??ti.setVariable("status", old+"(不同意)");
???? ??ti.end("不同意");
???? ?}
???? ?getContext().close();
???? }
?}
?
?public static void main(String[] args) {
??ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
??Test? test = (Test) context.getBean("jbpmTest");
??
??//test.createTable();
??//test.deployProcessionDefintion();
??//test.createInstance("s09报销单", "小李子");
??//test.writer("小李子", 3000, "坐车");
??//test.agree(6, false);
??
?}
?
?
?
?