引入Activiti配置文件activiti.cfg.xml
前面我们用代码实现了生成25张activiti表,今天我们用Activiti提供的activiti.cfg.xml配置文件来简化实现前面的功能;
官方文档参考地址:http://activiti.org/userguide/index.html#configuration
我们先在src/test/resources下创建一个xml文件 名字是:activiti.cfg.xml
然后我们从官方文档贴下参考的xml代码:
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 当然还有下面的配置我们可以去掉一些 后面会降到这些配置的用途;
修改完后的xml如下:
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 > |
接下来我们就是要通过代码来读取配置文件,然后获取工作流引擎实例:
代码如下:
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数据下的表 全部删除;
然后运行上面的测试类,我们会发现 表自动生成了:
表依然是前面的25张表;
我们会发现,使用xml配置会简化很多东西。。
完整代码打包下载:http://pan.baidu.com/s/1nuSJ3kd
mysql
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~