一 pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
<relativePath/>
</parent>
<groupId>com.syc.activiti</groupId>
<artifactId>activiti6-helloworld</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-engine</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.11</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.3.176</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--引入dbcp依赖包-->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
二 配置文件
<?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">
<!-- 使用DBCP数据源 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/act" />
<property name="username" value="root" />
<property name="password" value="123456" />
</bean>
<!-- 配置自定义属性 -->
<bean id="processEngineConfiguration" class="com.syc.activiti.MyConfiguration">
<property name="dataSource" ref="dataSource" />
<property name="databaseSchemaUpdate" value="drop-create"></property>
<property name="userName" value="crazyit"></property>
</bean>
</beans>
三 自定义ProcessEngineConfiguration
package com.syc.activiti;
import org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl;
import org.activiti.engine.impl.interceptor.CommandInterceptor;
public class MyConfiguration extends ProcessEngineConfigurationImpl {
public MyConfiguration() {
// 做自定义设置
}
@Override
public CommandInterceptor createTransactionInterceptor() {
return null;
}
//测试属性,需要在processEngineConfiguration注入
private String userName;
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return this.userName;
}
}
四 测试文件
package com.syc.activiti;
import org.activiti.engine.ProcessEngineConfiguration;
public class ConfigTest {
public static void main(String[] args) {
//创建ProcessEngineConfiguration,并强制转换为MyConfiguration
MyConfiguration config = (MyConfiguration)ProcessEngineConfiguration.
createProcessEngineConfigurationFromResource("my-config.xml");
config.buildProcessEngine();
//打印出结果为crazyit
System.out.println(config.getUserName());
}
}
五 测试结果
crazyit
六 数据库变化
只有act_ge_property数据表会产生数据。
mysql> select * from act_ge_property;
+--------------------------------------+-----------------+------+
| NAME_ | VALUE_ | REV_ |
+--------------------------------------+-----------------+------+
| cfg.execution-related-entities-count | false | 1 |
| next.dbid | 2501 | 2 |
| schema.history | create(6.0.0.4) | 1 |
| schema.version | 6.0.0.4 | 1 |
+--------------------------------------+-----------------+------+
4 rows in set (0.00 sec)
来源:oschina
链接:https://my.oschina.net/u/4261335/blog/3234194