Commit 1328bbc5 by ethanlamzs

暂时可以 实现 activiti 与 spring boot的集成 -- beta 状态

1 parent 753d4d10
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version> <version>1.5.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<activiti.version>6.0.0</activiti.version>
<mysql.version>5.1.46</mysql.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -35,6 +37,26 @@ ...@@ -35,6 +37,26 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-basic</artifactId>
<version>${activiti.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jdbc</artifactId>
<version>8.0.15</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -2,13 +2,25 @@ package com.qtone.wx.activititutorial; ...@@ -2,13 +2,25 @@ package com.qtone.wx.activititutorial;
import java.util.Arrays; import java.util.Arrays;
import org.springframework.boot.SpringApplication; import org.activiti.engine.RepositoryService;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
@SpringBootApplication @Configuration
@ComponentScan
@EnableAutoConfiguration
public class ActivitiTutorialApplication { public class ActivitiTutorialApplication {
public static void main(String[] args) { public static void main(String[] args) {
...@@ -16,6 +28,7 @@ public class ActivitiTutorialApplication { ...@@ -16,6 +28,7 @@ public class ActivitiTutorialApplication {
} }
@Bean @Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) { public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> { return args -> {
...@@ -30,4 +43,35 @@ public class ActivitiTutorialApplication { ...@@ -30,4 +43,35 @@ public class ActivitiTutorialApplication {
}; };
} }
@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 DataSource database() {
return DataSourceBuilder.create()
.url("jdbc:mysql://115.28.171.4:3306/spring-boot-activiti?characterEncoding=UTF-8")
.username("root")
.password("123456")
.driverClassName("com.mysql.jdbc.Driver")
.build();
}
} }
package com.qtone.wx.activititutorial;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class MyService {
@Autowired
private RuntimeService runtimeService;
@Autowired
private TaskService taskService;
@Transactional
public void startProcess() {
runtimeService.startProcessInstanceByKey("oneTaskProcess");
}
}
\ No newline at end of file \ No newline at end of file
File mode changed
spring.datasource.url=jdbc:mysql://115.28.171.4:3306/spring-boot-activiti?characterEncoding=utf8&useSSL=true
spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#自动创建、更新、验证数据库表结构
spring.jpa.properties.hibernate.hbm2ddl.auto=update
spring.jpa.show-sql=true
<?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>
\ No newline at end of file \ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!