activiti_SpringEnvironment

 

package main;





import org.activiti.engine.ProcessEngine;

import org.activiti.engine.ProcessEngines;

import org.activiti.engine.RepositoryService;

import org.activiti.engine.RuntimeService;

import org.activiti.engine.TaskService;

import org.activiti.engine.task.Task;



public class MyBusinessProcessTest2 {

  

    

  public static void main(String[] args) {

    // Create Activiti process engine

     // ProcessEngines.init();

     // System.out.println(ProcessEngines.getProcessEngines());

      ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

      RepositoryService repositoryService = processEngine.getRepositoryService();

        RuntimeService runtimeService = processEngine.getRuntimeService();

        // Deploy the process definition

        repositoryService.createDeployment()

          .addClasspathResource("main/MyBusinessProcessTest.simpleProcessTest.bpmn20.xml")

          .deploy();

     // Get the first task

        TaskService taskService = processEngine.getTaskService();

        

        runtimeService.startProcessInstanceByKey("simpleProcess");

        Task task = taskService.createTaskQuery().singleResult();

        taskService.complete(task.getId());

}

  

  /*public void simpleProcessTest() {

    runtimeService.startProcessInstanceByKey("simpleProcess");

    Task task = taskService.createTaskQuery().singleResult();

    //assertEquals("Write monthly financial report", task.getName());

  

    taskService.complete(task.getId());

    //assertEquals(0, runtimeService.createProcessInstanceQuery().count());

  }*/

} 


上面的代码会自动寻找activiti.cfg.xml文件。

<beans xmlns="http://www.springframework.org/schema/beans" 

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">



  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">

  

    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti" />

    <property name="jdbcDriver" value="com.mysql.jdbc.Driver" />

    <property name="jdbcUsername" value="root" />

    <property name="jdbcPassword" value="" />

    

    <property name="databaseSchemaUpdate" value="true" />

    

    <property name="jobExecutorActivate" value="false" />

    

    <property name="mailServerHost" value="mail.my-corp.com" /> 

    <property name="mailServerPort" value="5025" />    

  </bean>



</beans>

 

也会自动寻找activiti-context.xml文件,内容如下:

<?xml version="1.0" encoding="UTF-8"?>



<beans xmlns="http://www.springframework.org/schema/beans" 

       xmlns:context="http://www.springframework.org/schema/context"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.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-3.0.xsd">



  <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">

    <property name="driverClass" value="com.mysql.jdbc.Driver" />

    <property name="url" value="jdbc:mysql://localhost:3306/activiti" />

    <property name="username" value="root" />

    <property name="password" value="" />

  </bean>

  

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

    <property name="dataSource" ref="dataSource" />

  </bean>

  

  <!-- <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

      <property name="dataSource" ref="dataSource"/>

      <property name="jpaVendorAdapter">

          <bean class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">

              <property name="databasePlatform" value="org.apache.openjpa.jdbc.sql.H2Dictionary" />

          </bean>

      </property>

  </bean> -->



 <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">

    <property name="dataSource" ref="dataSource" />

    <property name="transactionManager" ref="transactionManager" />

    <property name="databaseSchemaUpdate" value="true" />

    <property name="mailServerHost" value="localhost" />

    <property name="mailServerPort" value="5025" />

    <!-- <property name="jpaEntityManagerFactory" ref="entityManagerFactory" />

    <property name="jpaHandleTransaction" value="true" />

    <property name="jpaCloseEntityManager" value="true" /> -->

    <property name="jobExecutorActivate" value="false" />

  </bean>

  

  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">

    <property name="processEngineConfiguration" ref="processEngineConfiguration" />

  </bean>

  

  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />

  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />

  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" />

  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />

  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />



</beans>

 

activiti-context.xml和activiti.cfg.xml这两个文件任意一个均可。

 

 

你可能感兴趣的:(Environment)