如何在Eclipse中为Activiti

时间:2017-09-29 14:00:19

标签: eclipse h2 activiti

Eclipse:Oxygen.1(4.7.1)

H2:1.3.176

Activiti:6.0.0

我是Activiti的新手,我只是想运行一个进程不使用内存数据库,而是切换到(createStandaloneProcessEngineConfiguration)以便默认的独立H2数据库。 关于这一点,我有两个问题:

  1. 用于流程引擎配置的createStandaloneProcessEngineConfiguration和createStandaloneInMemProcessEngineConfiguration之间的确切区别是什么。

  2. 虽然我想运行一个简单的项目,但它会抛出一些异常。

  3. 示例项目:

    public static void startBookOrder1() {
    ProcessEngine processEngine = ProcessEngineConfiguration
    .createStandaloneProcessEngineConfiguration()
    .buildProcessEngine(); 
    
    RepositoryService repositoryService = processEngine.getRepositoryService();
    RuntimeService runtimeService = processEngine.getRuntimeService();
    IdentityService identityService = processEngine.getIdentityService();
    TaskService taskService = processEngine.getTaskService(); 
    
    repositoryService.createDeployment()
    .addClasspathResource("bookorder.bpmn20.xml")
    .deploy();
    
    List<Task> availableTaskList = taskService.createTaskQuery().taskName("Work on order").list();
    for (Task task : availableTaskList) {
    taskService.complete(task.getId());
    } 
    
    Map<String, Object> variableMap = new HashMap<String, Object>();
    variableMap.put("isbn", "123456");
    identityService.setAuthenticatedUserId("kermit");
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
    "bookorder", variableMap);
    assertNotNull(processInstance.getId());
    List<Task> taskList = taskService.createTaskQuery().taskName("Work on order").list();
    assertEquals(1, taskList.size());
    System.out.println("found task " + taskList.get(0).getName());
    System.out.println("found task " );
    }
    

    例外

    Exception in thread "main" org.activiti.engine.ActivitiException: no activiti tables in db. set <property name="databaseSchemaUpdate" to value="true" or value="create-drop" (use create-drop for testing only!) in bean processEngineConfiguration in activiti.cfg.xml for automatic schema creation
    at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:989)
    at org.activiti.engine.impl.db.DbSqlSession.performSchemaOperationsProcessEngineBuild(DbSqlSession.java:1470)
    at org.activiti.engine.impl.SchemaOperationsProcessEngineBuild.execute(SchemaOperationsProcessEngineBuild.java:25)
    at org.activiti.engine.impl.interceptor.CommandInvoker.execute(CommandInvoker.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:57)
    at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:31)
    at org.activiti.engine.impl.cfg.CommandExecutorImpl.execute(CommandExecutorImpl.java:40)
    at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
    at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:427)
    at BookOrderTest.startBookOrder1(BookOrderTest.java:33)
    at BookOrderTest.main(BookOrderTest.java:26)
    Caused by: org.apache.ibatis.exceptions.PersistenceException: 
    ### Error querying database. Cause: org.h2.jdbc.JdbcSQLException: Table "ACT_GE_PROPERTY" not found; SQL statement:
    select VALUE_ from ACT_GE_PROPERTY where NAME_ = 'schema.version' [42102-176]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
    at org.h2.message.DbException.get(DbException.java:178)
    at org.h2.message.DbException.get(DbException.java:154)
    at org.h2.command.Parser.readTableOrView(Parser.java:5213)
    at org.h2.command.Parser.readTableFilter(Parser.java:1220)
    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1859)
    at org.h2.command.Parser.parseSelectSimple(Parser.java:1968)
    at org.h2.command.Parser.parseSelectSub(Parser.java:1853)
    at org.h2.command.Parser.parseSelectUnion(Parser.java:1674)
    at org.h2.command.Parser.parseSelect(Parser.java:1662)
    at org.h2.command.Parser.parsePrepared(Parser.java:434)
    at org.h2.command.Parser.parse(Parser.java:306)
    at org.h2.command.Parser.parse(Parser.java:278)
    at org.h2.command.Parser.prepareCommand(Parser.java:243)
    at org.h2.engine.Session.prepareLocal(Session.java:442)
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:265)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:160)
    at java.lang.Thread.run(Unknown Source)
    ### The error may exist in org/activiti/db/mapping/entity/Property.xml
    ### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntity.selectDbSchemaVersion
    ### The error occurred while executing a query
    ### SQL: select VALUE_ from ACT_GE_PROPERTY where NAME_ = 'schema.version'
    ### Cause: org.h2.jdbc.JdbcSQLException: Table "ACT_GE_PROPERTY" not found; SQL statement:
    select VALUE_ from ACT_GE_PROPERTY where NAME_ = 'schema.version' [42102-176]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
    at org.h2.message.DbException.get(DbException.java:178)
    at org.h2.message.DbException.get(DbException.java:154)
    at org.h2.command.Parser.readTableOrView(Parser.java:5213)
    at org.h2.command.Parser.readTableFilter(Parser.java:1220)
    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1859)
    at org.h2.command.Parser.parseSelectSimple(Parser.java:1968)
    at org.h2.command.Parser.parseSelectSub(Parser.java:1853)
    at org.h2.command.Parser.parseSelectUnion(Parser.java:1674)
    at org.h2.command.Parser.parseSelect(Parser.java:1662)
    at org.h2.command.Parser.parsePrepared(Parser.java:434)
    at org.h2.command.Parser.parse(Parser.java:306)
    at org.h2.command.Parser.parse(Parser.java:278)
    at org.h2.command.Parser.prepareCommand(Parser.java:243)
    at org.h2.engine.Session.prepareLocal(Session.java:442)
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:265)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:160)
    at java.lang.Thread.run(Unknown Source)
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:62)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:57)
    at org.activiti.engine.impl.db.DbSqlSession.getDbVersion(DbSqlSession.java:1011)
    at org.activiti.engine.impl.db.DbSqlSession.dbSchemaCheckVersion(DbSqlSession.java:967)
    ... 10 more
    Caused by: org.h2.jdbc.JdbcSQLException: Table "ACT_GE_PROPERTY" not found; SQL statement:
    select VALUE_ from ACT_GE_PROPERTY where NAME_ = 'schema.version' [42102-176]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:344)
    at org.h2.message.DbException.get(DbException.java:178)
    at org.h2.message.DbException.get(DbException.java:154)
    at org.h2.command.Parser.readTableOrView(Parser.java:5213)
    at org.h2.command.Parser.readTableFilter(Parser.java:1220)
    at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1859)
    at org.h2.command.Parser.parseSelectSimple(Parser.java:1968)
    at org.h2.command.Parser.parseSelectSub(Parser.java:1853)
    at org.h2.command.Parser.parseSelectUnion(Parser.java:1674)
    at org.h2.command.Parser.parseSelect(Parser.java:1662)
    at org.h2.command.Parser.parsePrepared(Parser.java:434)
    at org.h2.command.Parser.parse(Parser.java:306)
    at org.h2.command.Parser.parse(Parser.java:278)
    at org.h2.command.Parser.prepareCommand(Parser.java:243)
    at org.h2.engine.Session.prepareLocal(Session.java:442)
    at org.h2.server.TcpServerThread.process(TcpServerThread.java:265)
    at org.h2.server.TcpServerThread.run(TcpServerThread.java:160)
    at java.lang.Thread.run(Unknown Source)
    at org.h2.engine.SessionRemote.done(SessionRemote.java:567)
    at org.h2.command.CommandRemote.prepare(CommandRemote.java:67)
    at org.h2.command.CommandRemote.<init>(CommandRemote.java:46)
    at org.h2.engine.SessionRemote.prepareCommand(SessionRemote.java:439)
    at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1109)
    at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:74)
    at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:264)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.ibatis.datasource.pooled.PooledConnection.invoke(PooledConnection.java:245)
    at com.sun.proxy.$Proxy2.prepareStatement(Unknown Source)
    at org.apache.ibatis.executor.statement.PreparedStatementHandler.instantiateStatement(PreparedStatementHandler.java:72)
    at org.apache.ibatis.executor.statement.BaseStatementHandler.prepare(BaseStatementHandler.java:82)
    at org.apache.ibatis.executor.statement.RoutingStatementHandler.prepare(RoutingStatementHandler.java:54)
    at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:70)
    at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:56)
    at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:259)
    at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:132)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:105)
    at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:81)
    at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:104)
    ... 15 more
    

    我为H2数据库做了什么: 1.我将h2-1.3.176.jar文件复制到activiti libreries文件夹中。 2.我创建了一个文件&#39; activiti.cfg.xml&#39;在我的项目的这个方向:/ test / resources。它包含以下数据:

    activiti.cfg.xml

    &#13;
    &#13;
    <?xml version="1.0" encoding="UTF-8"?>
    <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" >
        <!-- Database configurations -->
        <property name="databaseType" value="h2" />
        <property name="jdbcUrl" value="jdbc:h2:tcp://localhost/activiti" />
        <property name="jdbcDriver" value="org.h2.Driver" />
        <property name="jdbcUsername" value="sa" />
        <property name="jdbcPassword" value="sa" />
        <property name="databaseSchemaUpdate" value="create-drop" />
      </bean>
      
    </beans>
    &#13;
    &#13;
    &#13;

    非常感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

错误表明未创建数据库表。 检查您的数据库并确认它们已创建。 此外,尝试手动创建表(使用提供的sql文件),看看是否有效。 这些都不是必要的,但是发生了一些奇怪的事情。