SpringBoot集成Camunda 启动失败

ERROR

***************************
APPLICATION FAILED TO START
***************************

Description:

Field processEngine in org.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration required a bean of type 'org.camunda.bpm.engine.ProcessEngine' that could not be found.


Action:

Consider defining a bean of type 'org.camunda.bpm.engine.ProcessEngine' in your configuration.


Solution

Spring Boot 2.1以上的版本不支持Camunda 需要将版本下调到 2.0.2.RELEASE.

Reason

Camunda配置类 CamundaBpmAutoConfiguration 上面有个Import 注解,注入了一个
SpringProcessEngineServicesConfiguration类, 在这里插入图片描述
然而SpringProcessEngineServicesConfiguration类中有个自动注入类,ProcessEngine 在这里插入图片描述
坑爹的就是,SpringProcessEngineServicesConfiguration中需要注入的ProcessEngine的ProcessEngineFactoryBean居然是在CamundaBpmAutoConfiguration类中通过@Bean 注解注入到容器中
在这里插入图片描述

猜测 (没有验证)

如果2.0.2的spring boot 是先加载CamundaBpmAutoConfiguration类中的@Bean 再加载@Import 那就没事,
2.1.0以上 是先加载@import 再加载@Bean 就大条了,SpringProcessEngineServicesConfiguration中的ProcessEngine就会在ProcessEngineFactoryBean初始化之前,被调用,于是就有上面的ERROR了;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: Spring Boot可以很方便地集成Camunda,只需要添加相应的依赖和配置即可。 1. 添加依赖 在pom.xml文件中添加以下依赖: ``` <dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId> <version>${camunda.version}</version> </dependency> ``` 其中,${camunda.version}是Camunda版本号,可以根据实际情况进行修改。 2. 配置Camunda 在application.properties文件中添加以下配置: ``` # Camunda配置 camunda.bpm.database.schema-update=true camunda.bpm.database.type=mysql camunda.bpm.database.jdbc-batch-processing=false camunda.bpm.job-execution.enabled=true camunda.bpm.job-execution.deployment-aware=true camunda.bpm.job-execution.lock-time-in-millis=300000 camunda.bpm.job-execution.max-jobs-per-acquisition=3 camunda.bpm.job-execution.max-wait=500 camunda.bpm.job-execution.wait-time-in-millis=500 camunda.bpm.process-engine.name=default camunda.bpm.process-engine.autodeployment-enabled=true camunda.bpm.webapp.index-redirect-enabled=true camunda.bpm.webapp.application-path=/camunda ``` 其中,需要根据实际情况修改数据库类型和连接信息。 3. 启动CamundaSpring Boot应用启动后,Camunda会自动启动并创建相应的数据库表。 4. 集成CamundaSpring Boot应用中,可以通过注入ProcessEngine来使用Camunda的功能,例如: ``` @Autowired private ProcessEngine processEngine; public void startProcessInstance() { ProcessInstance processInstance = processEngine.getRuntimeService() .startProcessInstanceByKey("myProcess"); } ``` 以上就是Spring Boot集成Camunda的简单步骤。 ### 回答2: Spring Boot是一个基于Spring框架的快速应用开发平台,可以轻松构建可扩展的应用程序。Camunda是一个流程引擎,它提供了一个完整的业务流程管理解决方案。通过将这两个工具集成在一起,可以获得更高效的流程开发和管理。 Spring Boot集成Camunda的过程如下: 1. 添加Camunda依赖和配置 在Spring Boot项目的pom.xml文件中添加Camunda的依赖: ``` <dependency> <groupId>org.camunda.bpm.springboot</groupId> <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId> <version>x.y.z</version> </dependency> ``` 然后在application.properties文件中添加以下配置信息: ``` spring.datasource.url=jdbc:h2:mem:camunda spring.datasource.driverClassName=org.h2.Driver spring.datasource.username=sa spring.datasource.password= # Camunda properties camunda.bpm.database.schema-update=true ``` 2. 创建业务流程 使用Camunda Modeler创建业务流程模型,并将其保存为.bpmn文件。然后将其复制到Spring Boot项目的resources/processes目录下。 3. 定义Camunda Service Tasks 为了使Camunda流程引擎能够访问Spring Bean,需要在Spring Boot项目中定义一个类,该类将通过Spring扫描自动发布为Camunda服务任务。该类应该包括一个或多个带有@ServiceTask注释的方法。 ``` @ServiceTask( id = "myServiceTask", name = "My Service Task", // The name of the delegate expression to be executed. // The expression is resolved to a Class<JavaDelegate> during the deployment process. delegateExpression = "${myDelegateExpression}", // Define the input parameters. variables = { @Variable(name = "input1", type = "string"), @Variable(name = "input2", type = "integer") }, // Define the output parameters. outputs = { @OutputParameter(name = "output1", type = "string"), @OutputParameter(name = "output2", type = "integer") } ) public class MyServiceTaskHandler implements JavaDelegate { @Override public void execute(DelegateExecution execution) throws Exception { // Implement your service logic here } } ``` 4. 发布Camunda流程 在Spring Boot项目启动时,Camunda会扫描资源目录下的流程文件,并将其发布到流程引擎中。你可以在Camunda的Cockpit中审查和管理这些流程。 使用Spring Boot集成Camunda,可以快速构建高效的业务流程管理解决方案。这个过程可能看起来有些复杂,但是一旦完成了,你将能够节省大量时间和精力来开发和管理自己的业务流程。 ### 回答3: Spring Boot是一款基于Spring Framework的Web开发框架,可以轻松集成各种组件和工具,包括Camunda,一个业务处理和工作流引擎。在Spring Boot的框架下,Camunda可以很轻松地集成到应用程序中,提供基于流程和任务的工作流管理和自定义业务处理能力。 下面是Spring Boot集成Camunda必须完成的几个步骤: 第一步:定义Camunda依赖 在pom.xml中,我们需要定义Camunda Spring Boot Starter依赖,此外,我们还需要为Camunda引擎、Camunda BPMN模型和Camunda REST API定义其他依赖,以及为启动应用程序的Spring Boot添加必要的资源和配置文件。 第二步:配置Camunda Engine 为Camunda Engine配置必要的属性和参数。我们可以在application.properties或application.yml中定义Camunda引擎的数据库url和连接参数、服务端口、日志级别等属性。 第三步:创建Camunda流程图 使用Camunda Modeler或其他流程建模工具创建BPMN 2.0流程图,该图指定了工作流程的各个步骤和条件。 第四步:定义Camunda service task 在流程图中,我们可以为任何任务节点定义一些Camunda service task,这些任务会调用Java或其他编程语言中的方法处理业务逻辑。Spring Boot框架为我们提供了可用于编写这些方法的框架,同时Camunda API可以与这些方法交互,使业务逻辑变得更加强大和灵活。 第五步:定义Camunda REST API 我们还可以使用Camunda REST API定义自定义REST服务,这些服务可以用于与其他业务系统或应用程序交互。 尽管集成Camunda需要完成上述步骤,但是使用Spring Boot的好处是,它非常简单,快速和灵活,可以轻松地完成Camunda集成和自定义。Spring Boot涉及的依赖项也非常广泛,涵盖了多个技术领域和功能,因此可以轻松地添加和管理Camunda和相关技术的扩展。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值