activiti工作流

0

DEMO地址:https://gitee.com/acgist/demo/tree/master/activiti

添加依赖

<dependency>
	<groupId>org.activiti</groupId>
	<artifactId>activiti-spring-boot-starter-basic</artifactId>
	<version>6.0.0</version>
</dependency>

出现异常:

Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_191]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_191]
	at java.lang.Class.forName0(Native Method) ~[na:1.8.0_191]
	at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_191]
	at org.springframework.util.ClassUtils.forName(ClassUtils.java:284) ~[spring-core-5.3.12.jar:5.3.12]
	at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:324) ~[spring-core-5.3.12.jar:5.3.12]
	... 24 common frames omitted

这个是自动配置没有引入Security,直接排除:

@SpringBootApplication(exclude = SecurityAutoConfiguration.class)

保存修改

添加依赖:

<dependency>
	<groupId>org.activiti</groupId>
	<artifactId>activiti-modeler</artifactId>
	<version>5.23.0</version>
</dependency>
<dependency>
	<groupId>org.activiti</groupId>
	<artifactId>activiti-json-converter</artifactId>
	<version>6.0.0</version>
</dependency>

添加扫描:

@ComponentScan({"org.activiti.rest.editor"})

注意这种情况必须添加activiti-json-converter不然启动提示:

Caused by: java.lang.ClassNotFoundException: org.activiti.bpmn.model.AdhocSubProcess
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_191]
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) ~[na:1.8.0_191]
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_191]
	... 55 common frames omitted

activiti-modeler默认加载了security,测试可以直接去掉权限:

@Configurable
@EnableWebSecurity
public static class AdminConfig extends WebSecurityConfigurerAdapter {
	@Override
	protected void configure(HttpSecurity http) throws Exception {
		http
			.csrf().disable()
			.antMatcher("/**").authorizeRequests().anyRequest().permitAll();
	}
}

如果不想导入activiti-modeler,我们可以自己实现保存加载,代码可以参考StencilsetRestResource/ModelEditorJsonRestResource/ModelSaveRestResource

编辑页面

Maven仓库下载activiti-webapp-explorer2.war,解压得到diagram-viewer/editor-app/modeler.html,复制到static目录。

修改配置app-cfg.js

ACTIVITI.CONFIG = {
	'contextRoot' : '',
};

如果没有修改路径直接改为空字符串

生产图片中文乱码

this.processEngineConfiguration.setLabelFontName("宋体");
this.processEngineConfiguration.setActivityFontName("宋体");
this.processEngineConfiguration.setAnnotationFontName("宋体");

ID生成策略

默认使用DbIdGenerator,长度不一样而且很难看,分布式不安全,想要修改,但是官方只有旧版XML配置,SpringBoot自动配置直接写死代码了。
自己实现了一个逻辑,可以实现修改ID策略,但是没有经过大量测试谨慎使用

if(processEngineConfiguration instanceof SpringProcessEngineConfiguration) {
	final IdGenerator idGenerator = new IdGenerator() {
		@Override
		public String getNextId() {
			// TODO:自行实现
			return System.nanoTime() + "";
		}
	};
	final SpringProcessEngineConfiguration springProcessEngineConfiguration = (SpringProcessEngineConfiguration) processEngineConfiguration;
	springProcessEngineConfiguration.setIdGenerator(idGenerator);
	springProcessEngineConfiguration.getBpmnDeployer().setIdGenerator(idGenerator);
	springProcessEngineConfiguration.getDbSqlSessionFactory().setIdGenerator(idGenerator);
}