在上一篇博客基础上,用xml的配置方式生成需要的25张表
1.先在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配置文件的方式。
具体表含义见上一篇博客
原博客传送门