1. idea를 사용하여 springboot 프로젝트 만들기
프로젝트의 pom에 관련 종속성을 도입합니다. 생성된 테이블은 mysql 데이터베이스에 배치되고 관련 구성은 구성 파일 application.yml
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <parent> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-parent</artifactid> <version>2.2.1.release</version> <relativepath/> <!-- lookup parent from repository --> </parent> <groupid>com.example</groupid> <artifactid>activiti</artifactid> <version>0.0.1-snapshot</version> <name>activiti</name> <description>demo project for spring boot</description> <properties> <project.build.sourceencoding>utf-8</project.build.sourceencoding> <project.reporting.outputencoding>utf-8</project.reporting.outputencoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-jdbc</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-web</artifactid> </dependency> <dependency> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-starter-test</artifactid> <scope>test</scope> </dependency> <dependency> <groupid>org.activiti</groupid> <artifactid>activiti-spring-boot-starter</artifactid> <version>7.0.0.beta2</version> </dependency> <dependency> <groupid>org.mybatis</groupid> <artifactid>mybatis</artifactid> <version>3.4.5</version> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.27</version> </dependency> <dependency> <groupid>org.projectlombok</groupid> <artifactid>lombok</artifactid> <optional>true</optional> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.springframework.boot</groupid> <artifactid>spring-boot-maven-plugin</artifactid> </plugin> </plugins> </build> </project>
에 추가되어야 합니다. 3.springsecurity 보안 프레임워크 통합 구성 추가
activiti7을 springboot와 통합한 후 기본적으로 springsecurity가 통합되므로 springsecurity에 통합된 관련 사용자 권한 구성 정보를 준비해야 합니다
1) securityutil 클래스를 추가합니다.
springsecurity 보안 프레임워크의 구성을 빠르게 구현하기 위해 구성 요소가 추가됩니다.
server: port: 8085 spring: application: name: spring-activiti datasource: url: jdbc:mysql://localhost:3306/activiti?useunicode=true&characterencoding=utf8&servertimezone=gmt&nullcatalogmeanscurrent=true username: root password: 123456 driver-class-name: com.mysql.jdbc.driver activiti: #1.flase: 默认值。activiti在启动时,会对比数据库表中保存的版本,如果没有表或者版本不匹配,将抛出异常 #2.true: activiti会对数据库中所有表进行更新操作。如果表不存在,则自动创建 #3.create_drop: 在activiti启动时创建表,在关闭时删除表(必须手动关闭引擎,才能删除表) #4.drop-create: 在activiti启动时删除原来的旧表,然后在创建新表(不需要手动关闭引擎) database-schema-update: true #检测历史表是否存在 db-history-used: true #记录历史等级 可配置的历史级别有none, activity, audit, full history-level: full #校验流程文件,默认校验resources下的processes文件夹里的流程文件 check-process-definitions: false
이 클래스는 activiti7에서 제공하는 예제에서 찾을 수 있습니다.
2) Demoapplicationconfig 클래스를 추가합니다.
해당 기능은 springsecurity 프레임워크의 사용자 권한 구성을 구현하여 시스템에서 사용자 권한 정보를 사용할 수 있도록 하는 것입니다.
@component public class securityutil { private logger logger = loggerfactory.getlogger(securityutil.class); @autowired @qualifier("myuserdetailsservice") private userdetailsservice userdetailsservice; public void loginas(string username) { userdetails user = userdetailsservice.loaduserbyusername(username); if (user == null) { throw new illegalstateexception("user " + username + " doesn't exist, please provide a valid user"); } logger.info("> logged in as: " + username); securitycontextholder.setcontext(new securitycontextimpl(new authentication() { @override public collection<? extends grantedauthority> getauthorities() { return user.getauthorities(); } @override public object getcredentials() { return user.getpassword(); } @override public object getdetails() { return user; } @override public object getprincipal() { return user; } @override public boolean isauthenticated() { return true; } @override public void setauthenticated(boolean isauthenticated) throws illegalargumentexception { } @override public string getname() { return user.getusername(); } })); org.activiti.engine.impl.identity.authentication.setauthenticateduserid(username); } }
4) 테스트 클래스 생성
@configuration public class demoapplicationconfiguration { private logger logger = loggerfactory.getlogger(demoapplicationconfiguration.class); @bean public userdetailsservice myuserdetailsservice() { inmemoryuserdetailsmanager inmemoryuserdetailsmanager = new inmemoryuserdetailsmanager(); string[][] usersgroupsandroles = { {"salaboy", "password", "role_activiti_user", "group_activititeam"}, {"ryandawsonuk", "password", "role_activiti_user", "group_activititeam"}, {"erdemedeiros", "password", "role_activiti_user", "group_activititeam"}, {"other", "password", "role_activiti_user", "group_otherteam"}, {"system", "password", "role_activiti_user"}, {"admin", "password", "role_activiti_admin"}, }; for (string[] user : usersgroupsandroles) { list<string> authoritiesstrings = arrays.aslist(arrays.copyofrange(user, 2, user.length)); logger.info("> registering new user: " + user[0] + " with the following authorities[" + authoritiesstrings + "]"); inmemoryuserdetailsmanager.createuser(new user(user[0], passwordencoder().encode(user[1]), authoritiesstrings.stream().map(s -> new simplegrantedauthority(s)).collect(collectors.tolist()))); } return inmemoryuserdetailsmanager; } @bean public passwordencoder passwordencoder() { return new bcryptpasswordencoder(); } }
Running 결과:
@springboottest @slf4j class activitiapplicationtests { @autowired private processengine processengine; /** * 流程定义的部署 */ @test public void createdeploy() { repositoryservice repositoryservice = processengine.getrepositoryservice(); deployment deployment = repositoryservice.createdeployment() .addclasspathresource("diagram/holiday.bpmn")//添加bpmn资源 .addclasspathresource("diagram/holiday.png") .name("请假申请单流程") .deploy(); log.info("流程部署id:" + deployment.getname()); log.info("流程部署名称:" + deployment.getid()); } }
위 내용은 SpringBoot가 Activiti7을 통합하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!