Environment configuration

Project environment: JDK1.8 Tomcat7 Maven3.5 Development tool: IDEA Activiti7

Create a project

Goal: Create a Maven project that integrates with Activiti and automatically generates 25 database tablesCopy the code

The preparatory work

CREATE DATABASE activiti DEFAULT CHARACTER SET UTF8; The Activiti database will use BPMN graphics in your project, so install the actiBPM plugin as follows: In IDEA, use the shortcut keys Shift+Ctrl+Alt+S to open the environment centerCopy the code

Create a New Maven project

1. Click New Project to create a new Project

2. Select the Maven project to create

3. Fill in the project information

4. Set Maven information

5. Click FLSH to complete the project creation. The creation structure is as follows

6. Complete the Java, Resource and other source folders under the main folder in the project. In IDEA, use the shortcut keys Shift+Ctrl+Alt+S to open the environment center, select the main package, and right-click New Folder to create missing folders

7. After the file is created, click corresponding to the corresponding file source

8. Create activiti.cfg.xml under the Resources package

The code is as follows:

<? The XML version = "1.0" encoding = "utf-8"? > <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/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"/> The < 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>Copy the code

Create log4j.properties under the Resources package

The following code

# 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} [% 15.15 t] % % - 6 r - 5 p % 30.30 c # % x % m LOGFILE is set to be a  File appender using a PatternLayout. log4j.appender.LOGFILE=org.apache.log4j.FileAppender . Log4j appenders. LOGFILE. The File = / Users/apple/learning/study/activity/activity_01 / xis. The log log4j appenders. 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 - %mCopy the code

9. Create a test class in the test package and generate a database table file

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. Create ProcessEngineConfiguration object ProcessEngineConfiguration configuration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml"); / / 2. Create ProcessEngine object ProcessEngine ProcessEngine = configuration. BuildProcessEngine (); System.out.println(processEngine); } @test public void testGenTable2(){// Use the following method to generate table conditions //1. Activiti configuration file name must be activiti.cfg.xml / / 2. The bean's id must be "processEngineConfiguration ProcessEngine defaultProcessEngine = ProcessEngines.getDefaultProcessEngine(); System.out.println(defaultProcessEngine); }}Copy the code

10. The generated table structure is as follows

The last

Welcome to pay attention to the public number: the future has light, receive a line of large factory Java interview questions summary + the knowledge points learning thinking guide + a 300 page PDF document Java core knowledge points summary!