IDEAspring2.1.5Activiti7Swagger 2.9.2Druid 1.1.16mysql 5.7JAVA 8 2.新建Spring Boot项目
有点~~~
3.maven pom.xml配置细节
xml版本='1.0'编码='UTF-8'?项目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' modelVersion4.0.0/modelVersion 父groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-parent/artifactId 版本2。 1.5.RELEASE/版本relativePath/!--从存储库查找父级--/parent groupIdcom.reanod.workflow/groupId artifactIdreanod_workflow/artifactId version0.0.1-SNAPSHOT/版本名称reanod_workflow/名称descriptionReanod工作流程/描述属性java.version1.8/java .version /properties 依赖项依赖项groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId /dependency 依赖项groupIdorg.mybatis.spring.boot/groupId artifactIdmybatis-spring-boot-starter/artifactId version2.0.1/version /dependency dependency groupIdmysql/groupId artifactIdmysql-connector-java/artifactIdscoperuntime/scope /dependency dependency groupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope /dependency !-- Alidruid 数据源-- 依赖groupIdcom. alibaba/groupId artifactIddruid/artifactId version1.1.16/version /dependency !-- https://mvnrepository.com/artifact/org.activiti.dependencies/activiti-dependencies -- 依赖groupIdorg.activiti.dependencies/groupId artifactIdactiviti-dependency/artifactId version7.1.0。 M1/version typepom/type /dependency dependency groupIdorg.activiti/groupIdartifactIdactiviti-spring-boot-starter/artifactId version7.1.0.M1/version /dependency !-- Activiti生成流程图--依赖groupIdorg.activiti/groupIdartifactIdactiviti-image -generator/artifactId /dependency !-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -- 依赖groupIdorg.springframework.security/groupId artifactIdspring-security-core/artifactId version5.1.5.RELEASE/version /dependency !-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -- 依赖groupIdio.springfox/groupId artifactIdspringfox-swagger2/artifactId version2.9.2/version /dependency !-- https://mvnrepository.com/artifact/io.springfox /springfox-swagger-ui -- 依赖项groupIdio.springfox/groupId artifactIdspringfox-swagger-ui/artifactId version2.9.2/version /dependency /dependencies 构建插件插件groupIdorg.springframework.boot/groupId artifactIdspring-boot-maven-plugin/artifactId/plugin /plugins /build/project 4.配置文件application.yml
spring: #Activiti属性配置activiti: database-schema-update: true job-executor-activate: true # asyncExecutorEnabled属性设置设置true后将替换那些旧的Job执行器history-level: full db-history-used: true check-process-definitions: false #自动部署验证设置:true-on(默认),false-off datasource: url: jdbc:mysql://localhost:3306/reanod_workflow?useUnicode=truecharacterEncoding=utf-8useSSL=trueserverTimezone=UTCnullCatalogMeansCurrent=true username: root password3336 0 root driver-class-name333 60 com.mysql.cj。 jdbc.驱动程序类型: com.alibaba.druid.pool.DruidDataSource初始化模式:始终initialSize: 5 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUAL testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true#filters: stat,wall,log4j maxPoolPreparedStatementPerConnectionSize: 20 useGlobalDataSourceStat: true connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500logging: level: com.ascendant: 调试模式: console: '%d{yyyy-MM-dd HH:mm:ss.S } %clr(-%5p) %clr( $ {PID:- }){洋红色} --- %clr([%15.15t]){faint} %highlight(%-80.80logger{300}){青色} %clr(:) %m %n%wEx' swagger:enabled: true因为activiti示例中使用了org.springframework.security,所以需要在数据库中创建一张表
DROP TABLE IF EXISTS users ;CREATE TABLE users ( username VARCHAR(20) NOT NULL, PASSWORD VARCHAR(150) NOT NULL,enabled TINYINT(1) DEFAULT NULL, PRIMARY KEY (username)) ENGINE=INNODB DEFAULT CHARSET=utf8 ;DROP TABLE IF EXISTSauthorities;CREATE TABLEauthorities(id BIGINT(20) NOT NULL AUTO_INCRMENT, username VARCHAR(20) NOT NULL,authority VARCHAR(50) NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB DEFAULT CHARSET=utf8;配置修改,使用JdbcUserDetailsManager类使用数据库获取用户信息
导入org.slf4j.Logger;导入org.slf4j.LoggerFactory;导入org.springframework.beans.factory.annotation.Autowired;导入org.springframework.context.annotation.Bean;导入org.springframework.context.annotation.Configuration;导入org.springframework.security.config.annotation.web.builders.HttpSecurity;导入org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;导入org.springframework.security.core.userdetails.UserDetailsService;导入org.springframework .security.crypto.bcrypt.BCryptPasswordEncoder;导入org.springframework.security.crypto.password.PasswordEncoder;导入org.springframework.security.provisioning.JdbcUserDetailsManager;导入javax.sql.DataSource;导入java.util.Arrays;导入java. util.List;@Configurationpublic class ApplicationConfiguration extends WebSecurityConfigurerAdapter { private Logger logger=LoggerFactory.getLogger(ApplicationConfiguration.class); @Autowired私有数据源数据源; @Bean public UserDetailsService myUserDetailsService() { JdbcUserDetailsManager jdbcUserDetailsManager=new JdbcUserDetailsManager(dataSource) ; String[] [] usersGroupsAndRoles={ {'salaboy', '密码', 'ROLE_ACTIVITI_USER', 'GROUP_activitiTeam'}, {'ryandawsonuk', '密码', 'ROLE_ACTIVITI_USER', 'GROUP_activitiTeam'}, {'erdemedeiros', '密码', 'ROLE_ACTIVITI_USER', 'GROUP_activitiTeam'}, {'其他', '密码', 'ROLE_ACTIVITI_USER', 'GROUP_otherTeam'}, {'admin', '密码', 'ROLE_ACTIVITI_ADMIN'}, }; for (String[] user : usersGroupsAndRoles) { ListStringauthoritiesStrings=Arrays.asList(Arrays.copyOfRange(user, 2, user.length)); logger.info(' 正在注册新的user: ' + user[0] + ' 具有以下权限[' +authoritiesStrings + ' ]');//jdbcUserDetailsManager.createUser(new User(user[0],passwordEncoder().encode( user[1]),//authoritiesStrings.stream().map(s - new SimpleGrantedAuthority(s)).collect (Collectors.toList())));返回jdbcUserDetailsManager; @Override protected void configure(HttpSecurity http) 抛出异常{ http .csrf().disable() .authorizeRequests() .anyRequest() .authenticated() .and () .httpBasic(); } @Bean publicPasswordEncoderpasswordEncoder() { return new BCryptPasswordEncoder(); }} 5. 集成Druid
/* * @author xugjbr * @version 1.0br * @createDate 2019/05/30 14:51 br * @Description p /p */import com.alibaba.druid.pool.DruidDataSource;import com.alibaba.druid.support.http .StatViewServlet;导入com.alibaba.druid.support.http.WebStatFilter;导入org.springframework.boot.context.properties.ConfigurationProperties;导入org.springframework.boot.web.servlet.FilterRegistrationBean;导入org.springframework.boot.web .servlet.ServletRegistrationBean;导入org.springframework.context.annotation.Bean;导入org.springframework.context.annotation.Configuration;导入javax.sql.DataSource;导入java.util.Arrays;导入java.util.HashMap;导入java .util.Map;@Configurationpublic class DruidConfiguration { //将所有以spring.datasource为前缀的配置项加载到DataSource中@ConfigurationProperties(prefix='spring.datasource') @Bean public DataSource druidDataSource() { return new DruidDataSource (); } } @Bean public ServletRegistrationBean druidStatViewServlet() { ServletRegistrationBean servletRegistrationBean=new ServletRegistrationBean(new StatViewServlet(),'/druid/*'); MapString, String initParams=new HashMap(); //可配置的属性都在StatViewServlet及其父类下initParams.put('loginUsername', 'admin-druid'); initParams.put('登录密码', '111111'); servletRegistrationBean.setInitParameters(initParams);返回servletRegistrationBean; } @Bean public FilterRegistrationBean druidWebStatFilter( ) { FilterRegistrationBean filterRegistrationBean=new FilterRegistrationBean(new WebStatFilter()); MapString, String initParams=new HashMap(); initParams.put('排除', '*.js,*.css,/druid/*');过滤注册Bean。 setInitParameters(initParams); filterRegistrationBean.setUrlPatterns(Arrays.asList('/*'));返回过滤器注册Bean; 6. 集成Swagger
包com.reanod.workflow.config;导入org.springframework.beans.factory.annotation.Value;导入org.springframework.context.annotation.Bean;导入org.springframework.context.annotation.Configuration;导入springfox.documentation.builders .ApiInfoBuilder;导入springfox.documentation.builders.PathSelectors;导入springfox.documentation.builders.RequestHandlerSelectors;导入springfox.documentation.ser
vice.ApiInfo;import springfox.documentation.service.Contact;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2;/** * @author xugj<br> * @version 1.0<br> * @createDate 2019/05/29 17:37 <br> * @Description <p> Swagger2 配置文件 </p> */@EnableSwagger2@Configurationpublic class SwaggerConfig { //是否开启swagger,正式环境一般是需要关闭的,可根据springboot的多环境配置进行设置 @Value(value = "${swagger.enabled}") Boolean swaggerEnabled; @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) // 是否开启 .enable(swaggerEnabled).select() .apis(RequestHandlerSelectors.basePackage("com.reanod.workflow.controller")) .paths(PathSelectors.any()).build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("Reanod工作流API") .description("xugj | 高效码农") // 作者信息 .contact(new Contact("高效码农", "https://www.xugj520.cn", "514583562@qq.com")) .version("1.0.0") .build(); }}七、创建processes bpmn文件 <?xml version="1.0" encoding="UTF-8" standalone="yes"?><definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" expressionLanguage="http://www.w3.org/1999/XPath" id="m1559179417530" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema"> <process id="myProcess_1" isClosed="false" isExecutable="true" processType="None"> <startEvent id="startevent1" name="StartEvent"/> <userTask activiti:exclusive="true" id="usertask1" name="填写请假申请"/> <sequenceFlow id="_2" sourceRef="startevent1" targetRef="usertask1"/> <exclusiveGateway gatewayDirection="Unspecified" id="exclusivegateway1" name="请假时间判断(排他网关)"/> <sequenceFlow id="_4" sourceRef="usertask1" targetRef="exclusivegateway1"/> <userTask activiti:assignee="test" activiti:exclusive="true" id="usertask2" name="经理审批"/> <userTask activiti:assignee="test2" activiti:exclusive="true" id="usertask3" name="总监审批"/> <exclusiveGateway gatewayDirection="Unspecified" id="exclusivegateway2" name="请假时间判断(排他网关)"/> <endEvent id="endevent1" name="End"/> <sequenceFlow id="_9" name="大于3天" sourceRef="exclusivegateway1" targetRef="usertask3"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days>3}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="_10" name="小于等于3天" sourceRef="exclusivegateway1" targetRef="usertask2"> <conditionExpression xsi:type="tFormalExpression"><![CDATA[${days<=3}]]></conditionExpression> </sequenceFlow> <sequenceFlow id="_11" sourceRef="usertask2" targetRef="exclusivegateway2"/> <sequenceFlow id="_12" sourceRef="usertask3" targetRef="exclusivegateway2"/> <sequenceFlow id="_13" sourceRef="exclusivegateway2" targetRef="endevent1"/> </process> <bpmndi:BPMNDiagram documentation="background=#3C3F41;count=1;horizontalcount=1;orientation=0;width=842.4;height=1195.2;imageableWidth=832.4;imageableHeight=1185.2;imageableX=5.0;imageableY=5.0" id="Diagram-_1" name="New Diagram"> <bpmndi:BPMNPlane bpmnElement="myProcess_1"> <bpmndi:BPMNShape bpmnElement="startevent1" id="Shape-startevent1"> <omgdc:Bounds height="32.0" width="32.0" x="160.0" y="125.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask1" id="Shape-usertask1"> <omgdc:Bounds height="55.0" width="85.0" x="305.0" y="110.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway1" id="Shape-exclusivegateway1" isMarkerVisible="false"> <omgdc:Bounds height="32.0" width="32.0" x="445.0" y="115.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask2" id="Shape-usertask2"> <omgdc:Bounds height="55.0" width="85.0" x="540.0" y="55.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="usertask3" id="Shape-usertask3"> <omgdc:Bounds height="55.0" width="85.0" x="535.0" y="165.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="55.0" width="85.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="exclusivegateway2" id="Shape-exclusivegateway2" isMarkerVisible="false"> <omgdc:Bounds height="32.0" width="32.0" x="710.0" y="125.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endevent1" id="Shape-endevent1"> <omgdc:Bounds height="32.0" width="32.0" x="830.0" y="135.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="32.0" width="32.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="_13" id="BPMNEdge__13" sourceElement="exclusivegateway2" targetElement="endevent1"> <omgdi:waypoint x="742.0" y="141.0"/> <omgdi:waypoint x="830.0" y="151.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_12" id="BPMNEdge__12" sourceElement="usertask3" targetElement="exclusivegateway2"> <omgdi:waypoint x="620.0" y="192.5"/> <omgdi:waypoint x="710.0" y="141.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_2" id="BPMNEdge__2" sourceElement="startevent1" targetElement="usertask1"> <omgdi:waypoint x="192.0" y="141.0"/> <omgdi:waypoint x="305.0" y="137.5"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_4" id="BPMNEdge__4" sourceElement="usertask1" targetElement="exclusivegateway1"> <omgdi:waypoint x="390.0" y="137.5"/> <omgdi:waypoint x="445.0" y="131.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_9" id="BPMNEdge__9" sourceElement="exclusivegateway1" targetElement="usertask3"> <omgdi:waypoint x="477.0" y="131.0"/> <omgdi:waypoint x="535.0" y="192.5"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_11" id="BPMNEdge__11" sourceElement="usertask2" targetElement="exclusivegateway2"> <omgdi:waypoint x="625.0" y="82.5"/> <omgdi:waypoint x="710.0" y="141.0"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="_10" id="BPMNEdge__10" sourceElement="exclusivegateway1" targetElement="usertask2"> <omgdi:waypoint x="477.0" y="131.0"/> <omgdi:waypoint x="540.0" y="82.5"/> <bpmndi:BPMNLabel> <omgdc:Bounds height="0.0" width="0.0" x="0.0" y="0.0"/> </bpmndi:BPMNLabel> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram></definitions>八、编写业务代码
用户评论
哇!这个标题很吸引人,迫不及待地想了解更多关于SpringBoot2集成Activiti7、Swagger API和Druid连接池的内容!
有20位网友表示赞同!
Activiti7集成,Druid连接池,还有Swagger API,这篇文章简直是宝藏!
有6位网友表示赞同!
非常期待学习SpringBoot2与Activiti7的集成方法,这篇文章应该会提供很多帮助。
有7位网友表示赞同!
终于找到一篇关于SpringBoot2集成Activiti7的文章了,感谢分享!
有16位网友表示赞同!
Swagger API集成太棒了!这下可以轻松地测试API了。
有8位网友表示赞同!
Druid连接池在项目中确实很实用,这篇文章写的很详细。
有9位网友表示赞同!
SpringBoot2集成工作流程,Activiti7,Swagger API,Druid连接池,这篇文章简直是开发者必备!
有9位网友表示赞同!
期待看到代码示例,这样可以更好地理解集成流程。
有12位网友表示赞同!
这篇文章的标题太吸引人了,必须点进来看看!
有18位网友表示赞同!
Activiti7集成,我已经迫不及待地想尝试了!
有6位网友表示赞同!
Druid连接池的配置步骤很清晰,易于理解。
有20位网友表示赞同!
Swagger API的集成可以提升开发效率,节省很多时间。
有17位网友表示赞同!
SpringBoot2的集成指南,非常实用!
有5位网友表示赞同!
Activiti7与SpringBoot2的完美结合,这篇文章值得收藏!
有8位网友表示赞同!
Swagger API的文档化功能太棒了,可以轻松生成API文档。
有7位网友表示赞同!
Druid连接池的性能提升很明显,推荐使用。
有19位网友表示赞同!
SpringBoot2的强大功能,结合Activiti7、Swagger API和Druid连接池,简直是完美搭配!
有5位网友表示赞同!
这篇文章的内容非常丰富,涵盖了多个方面,值得认真阅读。
有20位网友表示赞同!
期待作者能够分享更多关于集成方面的经验和技巧。
有20位网友表示赞同!
感谢作者的分享,这篇文章对我的项目开发非常有帮助!
有13位网友表示赞同!