环境配置
项目环境:JDK1.8tomcat7maven3.5开发工具:IDEAactiviti7创建
创建项目
目标:maven项目,集成Activiti,并自动生成25个数据库表在
准备工作
数据库中运行:createdatabaseactivitidefaultcharactersetutf 8;
用于创建Activiti数据库
因为项目使用BPMN图形,所以首先安装actiBPM插件。 安装方法为以下:
在IDEA中使用快捷键Shift Ctrl Alt S打开环境中心
单击
新建一个maven项目
1.newproject创建新项目
选择maven项目创建
3 .填写项目信息
设置maven信息
单击flsh完成项目创建,创建结构如下
6 .打开位于IDEA上的实用快捷方式Shift Ctrl Alt S环境中心,以补充项目中主文件夹下的源文件(如java和resource ),选择主包,然后右键单击new folder
7 .创建完成后,单击对应的文件源进行对应
在resources包下创建activiti.cfg.xml
代码为以下:
? XML版本=' 1.0 '编码=' utf-8 '?
beans xmlns=' http://www.spring framework.org/schema/beans '
xmlns 3360 xsi=' http://www.w3.org/2001/XML架构-instance '
xmlns 3360 context=' http://www.spring framework.org/schema/context '
xmlns : tx=' http://www.spring framework.org/schema/tx '
xsi :方案定位=' http://www.spring framework.org/schema/beans 3358 www.spring framework.org/sch
ema/beans/spring-beans.xsd http://www.springframework.org/schema/contex http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://192.168.0.114:3306/activiti"/> <property name="username" value="root"/> <property name="password" value="123456"/> </bean> <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration"> <property name="dataSource" ref="dataSource"></property> <property name="databaseSchemaUpdate" value="true"/> </bean> </beans>9.在resources包下创建log4j.properties
代码如下
# Set root category priority to INFO and its only appender to CONSOLE. #log4j.rootCategory=INFO, CONSOLE debug info warn error fatal log4j.rootCategory=debug, CONSOLE, LOGFILE # Set the enterprise logger category to FATAL and its only appender to CONSOLE. log4j.logger.org.apache.axis.enterprise=FATAL, CONSOLE # CONSOLE is set to be a ConsoleAppender using a PatternLayout. log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout log4j.appender.CONSOLE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m # LOGFILE is set to be a File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender log4j.appender.LOGFILE.File=/Users/apple/学习/study/activity/activity_01/xis.log log4j.appender.LOGFILE.Append=true log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout log4j.appender.LOGFILE.layout.ConversionPattern=%d{ISO8601} %-6r [%15.15t] %-5p %30.30c %x - %m9.在test包下创建测试类,生成数据库表文件
import org.activiti.engine.ProcessEngine; import org.activiti.engine.ProcessEngineConfiguration; import org.activiti.engine.ProcessEngines; import org.junit.Test; /** * @author : YXC * @version : 1.0 * @description : * @date : 2020/11/17 16:50 */ public class ActivitiTest { @Test public void testGenTable(){ //1.创建ProcessEngineConfiguration对象 ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); //2.创建ProcessEngine对象 ProcessEngine processEngine = configuration.buildProcessEngine(); System.out.println(processEngine); } @Test public void testGenTable2(){ //使用下面这种方式生成表的条件 //1.activiti配置文件名称必须为activiti.cfg.xml //2.bean的id必须为"processEngineConfiguration" ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine(); System.out.println(defaultProcessEngine); } }10.生成表结构如下
最后
欢迎关注公众号:前程有光,领取一线大厂Java面试题总结+各知识点学习思维导+一份300页pdf文档的Java核心知识点总结!