之前生成Activiti25张表是使用Java类生成的,但是在实际的开发中是使用activiti.cfg.xml配置文件生成。
官方文档参考地址:http://activiti.org/userguide/index.html#configuration (英文看不懂可以用谷歌浏览器翻译功能)
先在src/test/resources下创建一个xml文件 名字是:activiti.cfg.xml
<?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> 接下来我们就是要通过代码来读取配置文件,然后获取工作流引擎实例:
/** * 使用xml配置 简化 */ @Test public void testCreateTableWithXml(){ // 引擎配置 ProcessEngineConfiguration pec=ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); // 获取流程引擎对象 ProcessEngine processEngine=pec.buildProcessEngine(); }
先把前面db_activiti数据下的表 全部删除:
然后运行上面的测试类,我们会发现 表自动生成了:
使用xml配置会简化很多东西,而且在正规情况下的项目都是使用这种读取.XMl配置文件的方式。
