activiti中实现TaskListener注入Spring的bean以及去除自带权限问题
实现TaskListener监听器,使用默认生成的代码,是无法在监听器里面注入我们需要的bean(@Autowired和@Resource获取到的bean都是null),这里做下笔记。
第一步
此时需要把bpmn中这样设置,sendDocumentStartListener是监听器的类名(在这里首字母要小写)
<userTask activiti:assignee="${assignee}" activiti:exclusive="true" id="_3" name="order_verify_1"> <extensionElements> <activiti:taskListener event="create" delegateExpression="${taskListenerImp}" /> </extensionElements> </userTask>
第二步
监听器里要这么写(注意要加上@Component注解)
@Component public class TaskListenerImp implements TaskListener , JavaDelegate { @Autowired RuntimeService runtimeservice; @Override public void notify(DelegateTask delegateTask) { System.out.println(runtimeservice); } @Override public void execute(DelegateExecution var1){ } }
此时就可以注入Spring的bean了
2、activiti7+springboot 关闭禁用springsecurity
(注释)
原文链接:https://blog.csdn.net/jl19861101/article/details/100112029
Spring Boot v2.1.7.RELEASE
Spring v5.1.4.RELEASE
Activiti 7.1.0.M3.1
@SpringBootApplication(
exclude = {
org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration.class,
org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration.class
}
)
亲测可用
完整pom配置
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.rockadmin</groupId> <artifactId>rockadmin</artifactId> <version>1.0.1</version> <packaging>jar</packaging> <name>rockadmin</name> <description>admin manager dashboard</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.7.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <!-- <parent>--> <!-- <artifactId>micro-service-frame</artifactId>--> <!-- <groupId>com.rock</groupId>--> <!-- <version>0.0.1-SNAPSHOT</version>--> <!-- </parent>--> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>11</java.version> <mybatisplus-spring-boot-starter.version>1.0.4</mybatisplus-spring-boot-starter.version> <velocity.version>1.7</velocity.version> <activiti-dependencies.version>7.1.0.M3.1</activiti-dependencies.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.activiti.dependencies</groupId> <artifactId>activiti-dependencies</artifactId> <version>${activiti-dependencies.version}</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <!--web --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-configuration-processor</artifactId> <optional>true</optional> </dependency> <!-- ehchache --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-cache</artifactId> </dependency> <!-- SpringWebSocket依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency> <!-- 添加redis支持--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> <!-- 添加activiti支持 --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <exclusions> <!-- <exclusion>--> <!-- <groupId>org.springframework.security</groupId>--> <!-- <artifactId>spring-security-config</artifactId>--> <!-- </exclusion>--> <!-- <exclusion>--> <!-- <groupId>org.springframework.security</groupId>--> <!-- <artifactId>spring-security-web</artifactId>--> <!-- </exclusion>--> <!-- <exclusion>--> <!-- <groupId>org.springframework.security</groupId>--> <!-- <artifactId>spring-security-core</artifactId>--> <!-- </exclusion>--> <!-- <exclusion>--> <!-- <groupId>org.springframework.boot</groupId>--> <!-- <artifactId>spring-boot-starter-security</artifactId>--> <!-- </exclusion>--> <!-- <exclusion>--> <!-- <groupId>org.activiti.core.common</groupId>--> <!-- <artifactId>activiti-spring-security</artifactId>--> <!-- </exclusion>--> <!-- <exclusion>--> <!-- <groupId>org.activiti.core.common</groupId>--> <!-- <artifactId>activiti-spring-security-policies</artifactId>--> <!-- </exclusion>--> </exclusions> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-image-generator</artifactId> </dependency> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-json-converter</artifactId> </dependency> <!-- <dependency>--> <!-- <groupId>com.baomidou</groupId>--> <!-- <artifactId>mybatis-plus-boot-starter</artifactId>--> <!-- <version>3.1.1</version>--> <!-- </dependency>--> <!-- <dependency>--> <!-- <groupId>com.baomidou</groupId>--> <!-- <artifactId>mybatis-plus-generator</artifactId>--> <!-- <version>3.0.7.1</version>--> <!-- </dependency>--> <dependency> <groupId>batik</groupId> <artifactId>batik-transcoder</artifactId> <version>1.6-1</version> </dependency> <dependency> <groupId>com.github.theborakompanioni</groupId> <artifactId>thymeleaf-extras-shiro</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> </dependency> <!--mybatis --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.4</version> </dependency> <!--druid --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.19</version> </dependency> <!--commons --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.6</version> </dependency> <dependency> <groupId>commons-configuration</groupId> <artifactId>commons-configuration</artifactId> <version>1.10</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.5</version> </dependency> <!--shiro --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-core</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-spring</artifactId> <version>1.3.2</version> </dependency> <!-- shiro ehcache --> <dependency> <groupId>org.apache.shiro</groupId> <artifactId>shiro-ehcache</artifactId> <exclusions> <exclusion> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> </exclusion> </exclusions> <version>1.4.0</version> </dependency> <!-- utils --> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.31</version> </dependency> <!--velocity代码生成使用模板 --> <dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> </dependency> <dependency> <groupId>org.quartz-scheduler</groupId> <artifactId>quartz</artifactId> <version>2.2.1</version> <exclusions> <exclusion> <artifactId>slf4j-api</artifactId> <groupId>org.slf4j</groupId> </exclusion> </exclusions> </dependency> <!--swagger2--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.9.0</version> </dependency> <!-- xss过滤组件 --> <dependency> <groupId>org.jsoup</groupId> <artifactId>jsoup</artifactId> <version>1.9.2</version> </dependency> <!--war包部署需要--> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-web</artifactId>--> <!--<!– 移除嵌入式tomcat插件 –>--> <!--<exclusions>--> <!--<exclusion>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-tomcat</artifactId>--> <!--</exclusion>--> <!--</exclusions>--> <!--</dependency>--> <!--<dependency>--> <!--<groupId>javax.servlet</groupId>--> <!--<artifactId>javax.servlet-api</artifactId>--> <!--<version>3.1.0</version>--> <!--<scope>provided</scope>--> <!--</dependency>--> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable> </configuration> </plugin> </plugins> </build> <!--<repositories>--> <!--<repository>--> <!--<id>public</id>--> <!--<name>aliyun nexus</name>--> <!--<url>http://maven.aliyun.com/nexus/content/groups/public/</url>--> <!--<releases>--> <!--<enabled>true</enabled>--> <!--</releases>--> <!--</repository>--> <!--</repositories>--> <!--<pluginRepositories>--> <!--<pluginRepository>--> <!--<id>public</id>--> <!--<name>aliyun nexus</name>--> <!--<url>http://maven.aliyun.com/nexus/content/groups/public/</url>--> <!--<releases>--> <!--<enabled>true</enabled>--> <!--</releases>--> <!--<snapshots>--> <!--<enabled>false</enabled>--> <!--</snapshots>--> <!--</pluginRepository>--> <!--</pluginRepositories>--> </project>
————————————————