前面咱们用代码实现了生成25张activiti表,今天咱们用Activiti提供的activiti.cfg.xml配置文件来简化实现前面的功能;html
官方文档参考地址:http://activiti.org/userguide/index.html#configuration java
咱们先在src/test/resources下建立一个xml文件 名字是:activiti.cfg.xmlmysql
而后咱们从官方文档贴下参考的xml代码:spring
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<
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:h2:mem:activiti;DB_CLOSE_DELAY=1000"
/>
<
property
name
=
"jdbcDriver"
value
=
"org.h2.Driver"
/>
<
property
name
=
"jdbcUsername"
value
=
"sa"
/>
<
property
name
=
"jdbcPassword"
value
=
""
/>
<
property
name
=
"databaseSchemaUpdate"
value
=
"true"
/>
<
property
name
=
"jobExecutorActivate"
value
=
"false"
/>
<
property
name
=
"asyncExecutorEnabled"
value
=
"true"
/>
<
property
name
=
"asyncExecutorActivate"
value
=
"false"
/>
<
property
name
=
"mailServerHost"
value
=
"mail.my-corp.com"
/>
<
property
name
=
"mailServerPort"
value
=
"5025"
/>
</
bean
>
</
beans
>
|
这里的话,咱们要根据咱们的项目 修改jdbcUrl jdbcDriver jdbcUsername jdbcPassword 固然还有下面的配置咱们能够去掉一些 后面会降到这些配置的用途;sql
修改完后的xml以下:async
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?
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"
>
<
property
name
=
"jdbcUrl"
value
=
"jdbc:mysql://localhost:3306/db_activiti"
/>
<
property
name
=
"jdbcDriver"
value
=
"com.mysql.jdbc.Driver"
/>
<
property
name
=
"jdbcUsername"
value
=
"root"
/>
<
property
name
=
"jdbcPassword"
value
=
"123456"
/>
<
property
name
=
"databaseSchemaUpdate"
value
=
"true"
/>
</
bean
>
</
beans
>
|
接下来咱们就是要经过代码来读取配置文件,而后获取工做流引擎实例:ide
代码以下:测试
1
2
3
4
5
6
7
8
9
10
|
/**
* 使用xml配置 简化
*/
@Test
public
void
testCreateTableWithXml(){
// 引擎配置
ProcessEngineConfiguration pec=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource(
"activiti.cfg.xml"
);
// 获取流程引擎对象
ProcessEngine processEngine=pec.buildProcessEngine();
}
|
而后咱们测试的时候 先把前面db_activiti数据下的表 所有删除;ui
而后运行上面的测试类,咱们会发现 表自动生成了:spa
表依然是前面的25张表;
咱们会发现,使用xml配置会简化不少东西。。
完整代码打包下载:http://pan.baidu.com/s/1nuSJ3kd