💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
课件代码:https://gitee.com/flymini/codes01/tree/master/flowable_/learn-flowable03 **** 步骤如下: <br/> **1. 创建一个 maven 项目,`pom.xml`如下** ```xml <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <flowable.version>6.3.0</flowable.version> <slf4j.version>1.6.6</slf4j.version> <log4j.version>1.2.12</log4j.version> </properties> <dependencies> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-engine</artifactId> <version>${flowable.version}</version> </dependency> <dependency> <groupId>org.flowable</groupId> <artifactId>flowable-spring</artifactId> <version>${flowable.version}</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.40</version> </dependency> <dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.6.9</version> </dependency> <!-- log start --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>${slf4j.version}</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-nop</artifactId> <version>${slf4j.version}</version> </dependency> <!-- log end --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.12</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>5.0.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.0.7.RELEASE</version> <scope>compile</scope> </dependency> </dependencies> ``` **2. `resources/log4j.properties`日志配置文件** ```properties log4j.rootLogger=DEBUG, CA log4j.appender.CA=org.apache.log4j.ConsoleAppender log4j.appender.CA.layout=org.apache.log4j.PatternLayout log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n ``` **3. 进行 Flowable 配置** ```java @Configuration public class FlowableConfig { /** * 1. 配置数据源 */ @Bean public DataSource dataSource() { SimpleDriverDataSource dataSource = new SimpleDriverDataSource(); dataSource.setDriverClass(Driver.class); dataSource.setUrl("jdbc:mysql://localhost:3306/flowable_spring02?useUnicode=true&amp;characterEncoding=UTF-8"); dataSource.setUsername("root"); dataSource.setPassword("root"); return dataSource; } /** * 2. 配置事务管理器 */ @Bean public PlatformTransactionManager transactionManager() { DataSourceTransactionManager transactionManager = new DataSourceTransactionManager(); transactionManager.setDataSource(this.dataSource()); return transactionManager; } /** * 3. 配置SpringProcessEngineConfiguration */ @Bean public SpringProcessEngineConfiguration processEngineConfiguration() { SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration(); //数据源 configuration.setDataSource(this.dataSource()); //事务管理器 configuration.setTransactionManager(this.transactionManager()); //表生成策略:DB_SCHEMA_UPDATE_TRUE(true)表存在则使用,不存在则创建 configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE); //false不使用异步处理 configuration.setAsyncExecutorActivate(false); //流程部署时自动生成对应的图片 configuration.setCreateDiagramOnDeploy(true); //生成流程图参数 configuration.setProcessDiagramGenerator(new DefaultProcessDiagramGenerator()); //流程图字体 configuration.setActivityFontName("宋体"); configuration.setAnnotationFontName("宋体"); configuration.setLabelFontName("宋体"); return configuration; } /** * 4. 配置ProcessEngineFactoryBean */ @Bean public ProcessEngineFactoryBean processEngineFactoryBean() { ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean(); processEngineFactoryBean.setProcessEngineConfiguration(this.processEngineConfiguration()); return processEngineFactoryBean; } /** * 5. 配置ProcessEngine */ @Bean public ProcessEngine processEngine() { try { return this.processEngineFactoryBean().getObject(); } catch (Exception e) { e.printStackTrace(); } return null; } /** * 6. 获取各种服务接口 **/ @Bean public RuntimeService runtimeService() { return processEngine().getRuntimeService(); } @Bean public IdentityService identityService() { return processEngine().getIdentityService(); } @Bean public TaskService taskService() { return processEngine().getTaskService(); } @Bean public HistoryService historyService() { return processEngine().getHistoryService(); } @Bean public ManagementService managementService() { return processEngine().getManagementService(); } @Bean public RepositoryService repositoryService() { return processEngine().getRepositoryService(); } @Bean public DynamicBpmnService dynamicBpmnService() { return processEngine().getDynamicBpmnService(); } @Bean public FormService formService() { return processEngine().getFormService(); } } ``` **4. 可以拿到各种服务接口了** (1)如果是在测试单元中可以使用注解`@ContextConfiguration`引入配置,然后获取接口。 ```java @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = FlowableConfig.class) public class FlowableTests { //获取各种服务接口 @Autowired private RepositoryService repositoryService; @Autowired private RuntimeService runtimeService; @Autowired private TaskService taskService; @Autowired private HistoryService historyService; @Autowired private ManagementService managementService; @Test @Transactional //这个事务,不需要可以拿掉 public void deploymentProcess() { //org.flowable.engine.impl.RepositoryServiceImpl@5b6e8f77 System.out.println(this.repositoryService); } ``` (2)不是在测试单元中可以如下获取各种接口。 ```java public class FlowableTests { @Test @Transactional //这个事务,不需要可以拿掉 public void deploymentProcess() { ApplicationContext applicationContext = new AnnotationConfigApplicationContext(FlowableConfig.class); RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class); //org.flowable.engine.impl.RepositoryServiceImpl@389562d6 System.out.println(repositoryService); } } ```