newbie using Activiti 6 and Springboot 2.0.1

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

newbie using Activiti 6 and Springboot 2.0.1

Hi

I'm finding it difficult to configure Activiti into a Spingboot application api.

First of all is it a viable thing to embed Activiti into an API type application for use within that application or should Activiti be run standalone - we are not going Activiti 7 while its in early release stages.

The error is due to bean definition but I'm not sure where the beans should be defined and how - if thats correct approach for version 6. Our standards with Springhboot 2 is to annotate beans in java rather than xml context.

any pointers to relevant pages appreciated

so far I have...

pom

<activiti.version>6.0.0</activiti.version>
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-engine</artifactId>
    <version>${activiti.version}</version>
</dependency>

main.../resouces/processes/one-task-process-bpm20.xml

<?xml version="1.0" encoding="UTF-8"?>
<definitions
        xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
        xmlns:activiti="http://activiti.org/bpmn"
        targetNamespace="Examples">
    <process id="oneTaskProcess" name="The One Task Process">
        <startEvent id="theStart" />
        <sequenceFlow id="flow1" sourceRef="theStart" targetRef="theTask" />
        <userTask id="theTask" name="my task" />
        <sequenceFlow id="flow2" sourceRef="theTask" targetRef="theEnd" />
        <endEvent id="theEnd" />
    </process>

</definitions>

Applicatio

@SpringBootApplication
public class Application {

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

@Bean
public CommandLineRunner init(final RepositoryService repositoryService,
final RuntimeService runtimeService,
final TaskService taskService) {

return new CommandLineRunner() {
@Override
public void run(String... strings) throws Exception {
System.out.println("Number of process definitions : "
+ repositoryService.createProcessDefinitionQuery().count());
System.out.println("Number of tasks : " + taskService.createTaskQuery().count());
runtimeService.startProcessInstanceByKey("oneTaskProcess");
System.out.println("Number of tasks after process start: " + taskService.createTaskQuery().count());
}
};

}
}

and getting error
APPLICATION FAILED TO START\r\n***************************\r\n\r\nDescription:\r\n\r\nParameter 0 of method init in com.santech.gcb.org.Application required a bean of type 'org.activiti.engine.RepositoryService' that could not be found.\r\n\r\n\r\nAction:\r\n\r\nConsider defining a bean of type 'org.activiti.engine.RepositoryService' in your configuration.\r\n","logger_name":"org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter","thread_name":"restartedMain","level":"ERROR","level_value":40000}

3 Replies
Highlighted
Member II

Re: newbie using Activiti 6 and Springboot 2.0.1

discovered activiti-spring dependency for pom.xml

<!-- Activiti worwflow start -->
<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-engine</artifactId>
    <version>${activiti.version}</version>
</dependency>

<dependency>
    <groupId>org.activiti</groupId>
    <artifactId>activiti-spring</artifactId>
    <version>${activiti.version}</version>
</dependency>
<!-- Activiti worwflow end -->

added @Bean's to Application.java

/*
* Activiti workflow configuration start
* remove from here to end if not required
*/
@Bean
public CommandLineRunner init(final RepositoryService repositoryService,
final RuntimeService runtimeService,
final TaskService taskService) {
return new CommandLineRunner() {
@Override
public void run(String... strings) throws Exception {
System.out.println("Number of process definitions : "
+ repositoryService.createProcessDefinitionQuery().count());
System.out.println("Number of tasks : " + taskService.createTaskQuery().count());
runtimeService.startProcessInstanceByKey("oneTaskProcess");
System.out.println("Number of tasks after process start: " + taskService.createTaskQuery().count());
}
};
}

@Bean
public SpringProcessEngineConfiguration processEngineConfiguration() {
return new SpringProcessEngineConfiguration();
}

@Bean
public ProcessEngineFactoryBean processEngine() {
ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean();
factoryBean.setProcessEngineConfiguration(processEngineConfiguration());
return factoryBean;
}
@Bean
public RepositoryService repositoryService() {
return processEngine().getProcessEngineConfiguration().getRepositoryService();
}

@Bean RuntimeService runtimeService(){
return processEngine().getProcessEngineConfiguration().getRuntimeService();
}

@Bean TaskService taskService(){
return processEngine().getProcessEngineConfiguration().getTaskService();
}
/*
* Activiti workflow configuration end
* remove to here from start if not required
*/

API App not starting but errors not clear yet - suspect the run() method isn't appropriate in this app

Process finished with exit code 0

Highlighted
Member II

Re: newbie using Activiti 6 and Springboot 2.0.1

removed run ijn favour of component

public class WorkflowService {

@Autowired
    private RepositoryService repositoryService;

@Autowired
    private ProcessEngine processEngine;

@Autowired
    private RuntimeService runtimeService;

public ProcessInstance getProcessInstance(String name) {
return runtimeService.startProcessInstanceByKey(name);
    }
}

Getting a SQL error, looking for org.h2.driver although config is set for oracle.

@Value("${spring.datasource.url}")
private String url;

@Value("${spring.datasource.username}")
private String username;

@Value("${spring.datasource.password}")
private String password;

@Value("${spring.datasource.driver-class-name}")
private String driver;
@Bean
@Primary
public DataSource dataSource() {
return DataSourceBuilder
            .create()
            .url(this.url)
            .driverClassName("oracle.jdbc.OracleDriver") //this.driver)
            .username(this.username)
            .password(this.password)
            .build();
}

WorflowCntroller

private final WorkflowService workflowService;

public WorkflowController(WorkflowService workflowService) {
Assert.notNull(workflowService, "workflowService must not be null!");

this.workflowService = workflowService;
}

Error creating bean with name 'workflowController' defined in file [C:\\Javawork\\org\\org-api\\target\\classes\\com\\santech\\gcb\\org\\controller\\WorkflowController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'workflowService': Unsatisfied dependency expressed through field 'processEngine'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver\r\n### The error may exist in org/activiti/db/mapping/entity/Property.xml\r\n### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntityImpl.selectDbSchemaVersion\r\n### The error occurred while executing a query\r\n### Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: org.h2.Driver","logger_name":"org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext","thread_name":"restartedMain","level":"WARN","level_value":30000}

Highlighted
Member II

Re: newbie using Activiti 6 and Springboot 2.0.1

added pom dependency

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>

now logging error

Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database.  Cause: org.h2.jdbc.JdbcSQLException: Connection is broken: \"java.net.ConnectException: Connection refused: connect: localhost\" [90067-197]\r\n### The error may exist in org/activiti/db/mapping/entity/Property.xml\r\n### The error may involve org.activiti.engine.impl.persistence.entity.PropertyEntityImpl.selectDbSchemaVersion\r\n### The error occurred while executing a query\r\n### Cause: org.h2.jdbc.JdbcSQLException: Connection is broken: \"java.net.ConnectException: Connection refused: connect: localhost\" [90067-197]","logger_name":"org.springframework.boot.web.servlet.context