springboot2.x+h2+activiti6环境搭建记录

由于需要用到activiti6工作流,经过艰难的配置终于把环境搭起来了,结合查的和自己踩的坑,记录下过程,以备后用。

1.eclipse安装activi插件

我的eclipse是Eclipse IDE for RCP and RAP Developers,在线安装一直失败,最终离线安装搞定。

参照https://blog.csdn.net/qq_24583853/article/details/85270214安装成功

2.配置h2数据库和activiti6

配置文件配置如下,采用本地文件方式存储

#配置数据库h2的参数
spring.datasource.url=jdbc:h2:./db/H2/testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=sa

spring.h2.console.enabled=true

spring.activiti.database-schema-update=true

spring.activiti.check-process-definitions=false
spring.activiti.process-definition-location-prefix: classpath:/processes/

3.pom的主要配置


        org.springframework.boot
        spring-boot-starter-parent
        2.2.6.RELEASE
         
    


            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.1.2
        

            com.h2database
            h2
            runtime
        

        
            org.activiti
            activiti-spring-boot-starter-basic
            6.0.0
        

    org.activiti
    activiti-common-rest
    6.0.0


            org.projectlombok
            lombok
            true
        

4.参数加载配置代码

对于数据库和mybatis参数用config配置类进行加载如下:

  • 
    @Configuration
    @ConfigurationProperties(prefix = "spring.datasource")
    @MapperScan(basePackages = { DataSourceConstants.MAPPER_PACKAGE }, sqlSessionFactoryRef = "mybatisSqlSessionFactory")
    public class DataSourceConfig {
    
        private String url;
    
        private String username;
    
        private String password;
        
        @Bean(name = "mybatisDataSource")
        public DataSource mybatisDataSource() {
            DruidDataSource dataSource = new DruidDataSource();
            dataSource.setDriverClassName("org.h2.Driver");
            dataSource.setUrl(url);
            dataSource.setUsername(username);
            dataSource.setPassword(password);
            return dataSource;
        }
    
        @Bean(name = "mybatisTransactionManager")
        public DataSourceTransactionManager mybatisTransactionManager() {
            return new DataSourceTransactionManager(mybatisDataSource());
        }
    
    	@Bean
    
    	public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
    		//防止前端不填值后端插入失败
    		sqlSessionFactory.getConfiguration().setJdbcTypeForNull(JdbcType.NULL);
    		return new SqlSessionTemplate(sqlSessionFactory);
    	}
        
        @Bean(name = "mybatisSqlSessionFactory")
        public SqlSessionFactory mybatisSqlSessionFactory(@Qualifier("mybatisDataSource") DataSource mybatisDataSource)
                throws Exception {
            final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
            sessionFactory.setDataSource(mybatisDataSource);
            sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver()
                    .getResources(DataSourceConstants.MAPPER_LOCATION));
          
            return sessionFactory.getObject();
        }
    
        public String getUrl() {
            return url;
        }
    
        public void setUrl(String url) {
            this.url = url;
        }
    
        public String getUsername() {
            return username;
        }
    
        public void setUsername(String username) {
            this.username = username;
        }
    
        public String getPassword() {
            return password;
        }
    
        public void setPassword(String password) {
            this.password = password;
        }
    
    }

    activiconfig

  • @Configuration
    	public class ActivitiConfig {
    	 
    	    @Value("${spring.datasource.url}")
    	    private String url;
    	 
    	    @Value("${spring.datasource.username}")
    	    private String userName;
    	 
    	    @Value("${spring.datasource.password}")
    	    private String password;
    	 
    	    @Value("${spring.datasource.driver-class-name}")
    	    private String driver;	 	
    	 
    	    @Bean
    	    public ProcessEngineConfiguration processEngineConfiguration() {
    	        ProcessEngineConfiguration processEngineConfiguration = new StandaloneProcessEngineConfiguration();
    	        // 连接数据库的配置
    	        processEngineConfiguration.setJdbcDriver(driver);
    	        processEngineConfiguration.setJdbcUrl(url);
    	        processEngineConfiguration.setJdbcUsername(userName);
    	        processEngineConfiguration.setJdbcPassword(password);
    	       // processEngineConfiguration.setAsyncExecutorActivate(true);
    	       // processEngineConfiguration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
    	        return processEngineConfiguration;
    	    }
    	    
    	   /* @Bean
    	    public ProcessEngine processEngine() {
    	        return processEngineConfiguration().buildProcessEngine();
    	    }
    	    */
    	    @Bean
    	    public RepositoryService repositoryService() {
    	        return processEngineConfiguration().buildProcessEngine().getRepositoryService();
    	    }
    	 
    	    @Bean
    	    public RuntimeService runtimeService() {
    	        return processEngineConfiguration().buildProcessEngine().getRuntimeService();
    	    }
    	 
    	    @Bean
    	    public TaskService taskService() {
    	        return processEngineConfiguration().buildProcessEngine().getTaskService();
    	    }
    	 
    	    @Bean
    	    public FormService formService() {
    	        return processEngineConfiguration().buildProcessEngine().getFormService();
    	    }
    	 
    	    @Bean
    	    public HistoryService historyService() {
    	        return processEngineConfiguration().buildProcessEngine().getHistoryService();
    	    }
    	 
    	    @Bean
    	    public ManagementService managementService() {
    	        return processEngineConfiguration().buildProcessEngine().getManagementService();
    	    }
    	 
    	    @Bean
    	    public IdentityService identityService() {
    	        return processEngineConfiguration().buildProcessEngine().getIdentityService();
    	    }
    	}

     

  • 启动类

  • @SpringBootApplication
    @EnableAutoConfiguration(exclude = {     
            org.activiti.spring.boot.SecurityAutoConfiguration.class
    })
    
    public class Application {
    
    	public static void main(String[] args) {
    		SpringApplication.run(Application.class, args);
    	}

    在启动类中,一定要加上剃掉security的权限校验,不然每次需要权限校验

  • 切记要在resources下创建目录processes,因为在配置文件里配置了扫描位置。

  • 以上就是自己搭建的过程,搭建中坑太多了,,,,,,,

 

你可能感兴趣的:(java)