Spring整合activiti配置processEngine

51 篇文章 0 订阅
12 篇文章 0 订阅

配置xml数据时,可以直接在配置文件中填写,也可以采用properties配置文件的方式加载

采用配置文件的方式需要使用到${参数}的方式获取。

引用配置文件的方式:<context:property-placeholder location="classpath:properties文件目录" />


applicationContaxt.xml配置信息如下所示

<?xml version="1.0" encoding="utf-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans     
        http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-4.2.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
        ">


<!-- Hibernate5 -->
<!-- 加载资源文件 其中包含变量信息,必须在Spring配置文件的最前面加载,即第一个加载 -->
<context:property-placeholder location="classpath:xxxxx.properties" />


<!-- 该 BeanPostProcessor 将自动对标注 @Autowired 的 Bean 进行注入 -->
<bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor" />


<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<!-- 可以加多个 -->
<value>cn/xxxx/xxxxx/xx.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.connection.SetBigStringTryClob">true</prop>
<prop key="hibernate.temp.use_jdbc_metadata_defaults">false</prop><!-- 不显示驱动关于lob的检测:Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException -->
<prop key="hibernate.jdbc.batch_size">50</prop>
<prop key="cache.use_second_level_cache">${cache.use_second_level_cache}</prop>
<prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>
<prop key="javax.persistence.validation.mode">none</prop>
<!-- <prop key="hibernate.current_session_context_class">thread</prop> hibernate4以上版本使用thread时不能使用事务托管,因其取得的session不是来源于spring了-->
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
</props>
</property>
</bean>


<!-- jndi外部连接池方式
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiName" value="XXX"/>
</bean> -->
<!-- 直接连接方式
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.user}" />
<property name="password" value="${jdbc.pass}" />
</bean> -->
<!-- 连接池方式 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClassName}" />
<property name="jdbcUrl" value="${jdbc.url}" />
<property name="user" value="${jdbc.user}" />
<property name="password" value="${jdbc.pass}" />
        <!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->  
        <property name="initialPoolSize" value="${c3p0.initialPoolSize}"/>
        <!--连接池中保留的最小连接数。Default: 3 -->
        <property name="minPoolSize" value="${c3p0.minPoolSize}"/>
        <!--连接池中保留的最大连接数。Default: 15 -->
        <property name="maxPoolSize" value="${c3p0.maxPoolSize}"/>
        <!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
        <property name="acquireIncrement" value="${c3p0.acquireIncrement}"/>
        <!-- 控制数据源内加载的PreparedStatements数量(全局)。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
        <property name="maxStatements" value="50"/>
        <!-- maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
        <property name="maxStatementsPerConnection" value="50"/>
        <!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
        <property name="maxIdleTime" value="1800"/>
<!-- 当连接池连接耗尽时,客户端调用getConnection()后等待获取新连接的时间,超时后将抛出SQLException,如设为0则无限期等待。单位毫秒。默认: 0 -->
<property name="checkoutTimeout" value="3000"/>
<!--定义在从数据库获取新连接失败后重复尝试的次数。默认值: 30 ;小于等于0表示无限次-->
<property name="acquireRetryAttempts" value="2"/>
<!--重新尝试的时间间隔,默认为:1000毫秒-->
<property name="acquireRetryDelay" value="2000"/>
<!--关闭连接时,是否提交未提交的事务,默认为false,即关闭连接,回滚未提交的事务 -->
        <property name="autoCommitOnClose" value="false"/>
<!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试使用。默认值: null -->
<!--<property name="automaticTestTable" value=""/>-->
<!--如果为false,则获取连接失败将会引起所有等待连接池来获取连接的线程抛出异常,但是数据源仍有效保留,并在下次调用getConnection()的时候继续尝试获取连接。如果设为true,那么在尝试获取连接失败后该数据源将申明已断开并永久关闭。默认: false-->   
<property name="breakAfterAcquireFailure" value="false"/>
<!--每60秒检查所有连接池中的空闲连接。默认值: 0,不检查 -->
<property name="idleConnectionTestPeriod" value="300"/>
</bean>

<!-- 配置Hibernate事务管理器 -->
<!--hibernate4以上必须配置为开启事务(可能为只读事务) 否则 getCurrentSession()获取不到--> 
<bean id="txManager"
class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>


<!-- 如果此处提示Error occured processing XML 'org/springframework/transaction/interceptor/TransactionInterceptor'.可以引入aopalliance-1.0.jar这个jar包来解决 -->
<tx:advice id="txAdvice" transaction-manager="txManager">
         <tx:attributes>
             <tx:method name="*_trans" propagation="REQUIRED" />
             <tx:method name="*" propagation="NEVER" read-only="true"/>
         </tx:attributes>
    </tx:advice>
<aop:config proxy-target-class="true">
<!--aop expression参考:http://blog.csdn.net/kkdelta/article/details/7441829 -->
         <!-- <aop:advisor advice-ref="txAdvice" pointcut="execution(* dao.*.*(..))"/> -->
         <aop:pointcut expression="execution(* cn.xxxx.dao.*.*(..)) or 
          execution(* xxx.yyy.zzzz.*.*(..))" id="pointcut"/>
         <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/>
     </aop:config>
     
<!-- activiti5集成spring配置,此为切入点,id不能改名,额外需要jackson相关包3个,
需要的架包参考用户手册集成说明内的,不要盲目的加入war示例内的所有jar -->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<!-- 配置的是ProcessEngineConfiguration.java类的属性 -->
<property name="dataSource" ref="dataSource" />
<property name="transactionManager" ref="txManager" />
<property name="databaseSchemaUpdate" value="false" /><!-- 此处通常应该为false -->
<property name="jobExecutorActivate" value="false" />
<property name="history" value="none" />
<property name="dbIdentityUsed" value="false" />
<property name="dbHistoryUsed" value="false" /><!-- 不检测历史表是否存在,应对Activiti database problem: Tables missing for component(s) history, identity -->
<!-- <property name="createDiagramOnDeploy" value="false" />发布时是否包括流程图片png-->
<property name="activityFontName" value="宋体"/><!-- 避免发布的图片和xml遇到中文时乱码 -->
   <property name="labelFontName" value="宋体"/>
   <property name="xmlEncoding" value="gbk"/><!-- 解析xml流程文件所使用的字符集,默认为utf8,依据数据库来 -->

</bean>

<!-- 引擎实例,通常就是用到它 -->
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration" />
</bean>

<!-- activiti流程的辅助类,仅后台发布和重绑流程用到 -->
<bean id="actDeploy" class="cn.xxxxx.activiti.ActDeploy">

</bean>


<!-- 创建activiti提供的各种服务 -->
<!-- 工作流仓储服务
<bean id="repositoryService" factory-bean="processEngine"
factory-method="getRepositoryService" /> -->
<!-- 工作流运行服务
<bean id="runtimeService" factory-bean="processEngine"
factory-method="getRuntimeService" /> -->
<!-- 工作流任务服务
<bean id="taskService" factory-bean="processEngine"
factory-method="getTaskService" /> -->
<!-- 工作流历史数据服务
<bean id="historyService" factory-bean="processEngine"
factory-method="getHistoryService" /> -->
<!-- 工作流管理服务
<bean id="managementService" factory-bean="processEngine"
factory-method="getManagementService" /> -->
<!-- 工作流唯一服务
<bean id="IdentityService" factory-bean="processEngine"
factory-method="getIdentityService" /> -->
</beans>
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
要将 Activiti 7 集成到 Spring Boot 应用程序中,可以按照以下步骤操作: 1. 添加依赖项 在 pom.xml 文件中添加以下依赖项: ``` <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter-basic</artifactId> <version>7.0.0.M6</version> </dependency> ``` 2. 配置数据源 在 application.properties 文件中添加以下配置: ``` spring.datasource.url=jdbc:mysql://localhost:3306/db_name?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&serverTimezone=UTC spring.datasource.username=username spring.datasource.password=password spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver ``` 3. 配置 Activiti 在 application.properties 文件中添加以下配置: ``` # Activiti spring.activiti.database-schema-update=true spring.activiti.history-level=full spring.activiti.check-process-definitions=true ``` 4. 创建流程定义 创建一个简单的 BPMN 文件并将其放置在 `src/main/resources/processes` 目录下。 5. 启动应用程序 现在可以启动应用程序并尝试部署和运行流程定义。 Activiti 7 提供了许多 API 和服务,可以在 Spring Boot 应用程序中使用,例如: - `ProcessEngine`: Activiti 引擎的主要入口点,提供了各种管理流程定义和执行实例的方法。 - `RepositoryService`: 管理流程定义的部署和查询。 - `RuntimeService`: 创建和管理流程实例。 - `TaskService`: 管理任务的分配和完成。 - `HistoryService`: 查询历史流程实例和任务。 可以通过注入这些服务来使用它们,例如: ``` @Autowired private ProcessEngine processEngine; ``` 这样可以在 Spring Boot 应用程序中使用 Activiti 7。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值