2018/01/30

Spring Boot starters for jBPM and KIE Server

jBPM supports Spring (and Spring Boot) for quite a while but it didn't provide it based on Spring Boot way - auto configuration and starters.

With upcoming release (7.6.0) this has changed. Now there are fully featured starters (based on auto configuration modules) for:

  • jBPM embedded
  • fully featured KIE Server
  • rules only KIE Server (Drools)
  • rules, processes and cases KIE Server (jBPM)
  • planning KIE Server (OptaPlanner)

You can very easily get started with these by using Spring Initializr (https://start.spring.io) where you can generate a complete project with all needed to get it running.

Have a look at this quick screencast that shows it in action.



Next take some time to read up guides for starters:
  • jBPM business process management - embedded engine
    •  groupId: org.kie
    •  artifactId: jbpm-spring-boot-starter-basic
    •  Guide
  • Fully featured KIE Server (Drools, jBPM, Optaplanner)
    •  groupId: org.kie
    •  artifactId: kie-server-spring-boot-starter
    •  Guide
  • Rules and Decisions KIE Server (Drools, DMN)
    •   groupId: org.kie
    •   artifactId: kie-server-spring-boot-starter-drools
    •   Guide
  • Rules and Decisions, Process and Cases KIE Server (Drools, DMN, jBPM, Case mgmt)
    •  groupId: org.kie
    •  artifactId: kie-server-spring-boot-starter-jbpm
    •  Guide
  • Planning KIE Server (Optaplanner)
    •  groupId: org.kie
    •  artifactId: kie-server-spring-boot-starter-optaplanner
    •  Guide


Last but not least, take a look at samples that are in the code base - especially one worth noting is KIE Server secured with Keycloak!

Stay tuned as more will come!

45 comments:

  1. Hi Maciej,
    first I have to say thanks for your great jBPM series :)
    I have two questions though.
    Is there any possibility to add custom scripts (javascript etc.) to the human task forms (created with the form builder), for example to calculate something at the client side (total after adding a new row to the data table and so on)?
    Can a parameter passed from the page be used within a data set to filter data directly in the database (as in the native strategy section of this document http://docs.jboss.org/dashbuilder/release/6.2.0.Final/html/chap-dashbuilder-first_steps.html)?

    Regards,
    robert

    ReplyDelete
    Replies
    1. Robert, in general there are options to use some kind of expressions in the forms but I don't know all the details so I would recommend to drop an email on jbpm usage mailing lists as guys working on forms could chime in. Similar for data sets.

      Delete
    2. Thank you!
      One more thing to ask - let's say I have defined some useful dashboards (pages and navigations) using KIE Workbench (v7.6.0). Now, I want to package them and release together with my application (kjars) to install in production. How can I achive that and are those assets versioned somehow?

      Regards,
      robert

      Delete
  2. Hello Maciej,

    are the starters for jBPM working now? I've tried start.spring.io with spring boot version 1.5.10 and it could not find dependencies for jBPM, KIE Server...
    Is it working now or it is planned to be introduced in the nearest future?

    Regards,
    Marek

    ReplyDelete
    Replies
    1. starters are available in 7.6.0 version of jBPM but unfortunately spring initializr team declined our PR to be included in the start.spring.io

      so you have to build your starters manually or build spring initializr app yourself (as I did when doing this article - was still hoping it will be included in spring :()

      take a look at the samples included https://github.com/kiegroup/droolsjbpm-integration/tree/master/kie-spring-boot/kie-spring-boot-samples

      Delete
    2. Thank you very much.
      Do you know the date that starters could be included in start.spring.io?

      Delete
    3. it won't be there. spring team decided to reject and not including it https://github.com/spring-io/initializr/pull/582

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. imported following ptoject:
    https://github.com/kiegroup/droolsjbpm-integration/tree/master/kie-spring-boot/kie-spring-boot-samples/jbpm-spring-boot-sample-basic

    @SpringBootApplication not getting resolved

    ReplyDelete
  5. Hello Maciej,

    could you please share somewhere the project that you developed in this article?
    I'm trying to follow your video with starter kie-server-spring-boot-starter but it is not working (problems with auto configuration and dependencies)
    When I use kie-server-spring-boot-sample the kie-server is running, but there is no kie-wb, but I'd like to have it in my project as it is in your video.

    ReplyDelete
    Replies
    1. there is no kie-wb for spring boot it's only the execution server. If you need kie wb then you need to run it in "traditional" way - deployed to wildfly for instance.

      what do you mean is not working, you need to be more specific as there is no way to help

      Delete
    2. About not working:
      1. After running with spring boot I'm getting error
      Failed to bind properties under 'spring.datasource.type' to java.lang.Class:

      Property: spring.datasource.type
      Value: org.apache.tomcat.jdbc.pool.XADataSource
      Origin: class path resource [application.properties]:12:24
      Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class]

      I'm using starter org.kie:kie-server-spring-boot-starter-jbpm:7.6.0.Final

      Delete
    3. looks like you're trying to run with spring boot 2.0.0 which this (7.6.0) version is not build for that spring boot version as it was not yet released. In general you can remove that property from application.properties though there is still one issue to make it run on spring boot 2.0.0 that was already addressed and will be part of 7.7.0 of jBPM.

      so for now you need to stick to spring boot 1.5.x with jBPM 7.6.0

      Delete
    4. I've tried it before but there (spring boot 1.5.10) is another problem with context:

      Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
      2018-03-22 09:59:27.232 ERROR 13640 --- [ main] o.s.boot.SpringApplication : Application startup failed

      org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at com.asseco.jbpm.JBpmBenchmarkMavenApplication.main(JBpmBenchmarkMavenApplication.java:10) [classes/:na]
      Caused by: org.springframework.context.ApplicationContextException: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean.
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.getEmbeddedServletContainerFactory(EmbeddedWebApplicationContext.java:189) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:162) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
      ... 8 common frames omitted

      Delete
    5. Hello Maciej,

      I succeeded with using one of your samples, but I would like to call spring Bean inside 'script task' and 'java service task', is it possible without creating my own work item handler?

      Regards,
      Marek

      Delete
    6. I think the easiest way would be to add ApplicationContext into environment and then in your script task you could do:
      ApplicationContext context = context.getKieRuntime.getEnvironmet().get("AppContext");
      context.getBean()

      to add the context to the environment you could either use some static helper class and declare it via deployment descriptor or override auto configuration bean runtimeManagerFactory https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-spring-boot/kie-spring-boot-autoconfiguration/jbpm-spring-boot-autoconfiguration/src/main/java/org/jbpm/springboot/autoconfigure/JBPMAutoConfiguration.java#L169

      you could the overload the SpringRuntimeManagerFactoryImpl - adjustEnvironment method and add the application context or even your beans that you want to use.

      Delete
    7. oh and feel free to open jira so we could look into it to improve this...

      Delete
    8. Thank You Maciej,

      your advice is really helpful.
      I'm trying to use ApplicationContext in Script Task.
      To do this Ineed to add org.springframework:spring-context:5.0.4.RELEASE in dependencies, but this lead to many warnings like '2018-03-26 08:37:22,861 WARN [org.kie.workbench.common.services.backend.builder.core.ClassVerifier] (default task-8) Verification of class org.springframework.context.support.BeanDefinitionDsl$profile$beans$1 failed and will not be available for authoring"
      What am I doing wrong?

      Marek

      Delete
    9. Could you also give me the example how to put appContext or Bean to the environment? Is it possible to made it from spring app code, using kieServer object?

      Delete
    10. this is what I had in mind:

      @Bean(name = "runtimeManagerFactory")
      public RuntimeManagerFactory runtimeManagerFactory(UserGroupCallback userGroupCallback, UserInfo userInfo, ApplicationContext appContext) {

      SpringRuntimeManagerFactoryImpl runtimeManager = new SpringRuntimeManagerFactoryImpl() {

      @Override
      protected void adjustEnvironment(RuntimeEnvironment environment) {

      super.adjustEnvironment(environment);
      ((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().set("AppContext", appContext);
      }

      };
      runtimeManager.setTransactionManager((AbstractPlatformTransactionManager) transactionManager);
      runtimeManager.setUserGroupCallback(userGroupCallback);
      runtimeManager.setUserInfo(userInfo);
      return runtimeManager;
      }

      this should replace the one from auto configuration and put in ApplicationContext into environment so will be available for each process execution.

      Delete
    11. these errors in workbench are due to classes you added as dependencies are scanned and attempted to be made available for authoring. You can mark them as provided and thus exclude them scanning.

      Delete
    12. Hello,

      I've overwritten the configuration as You said (I put my beans into environment template). I checked in log file that MY runtimeManageFactory bean is being defined, but in script task I couldn't get the bean from Environment. I'm getting error

      org.jbpm.workflow.instance.WorkflowRuntimeException: [process:1 652 - task:3] -- null

      I'm calling the bean as follows
      MybeanClass bean = (MyBeanClass)kcontext.getKieRuntime().getEnvironment().get("myBeanNme");
      bean.do();

      Am I doing anything wrong?

      Delete
    13. sorry, my bad you should use:

      ((SimpleRuntimeEnvironment)environment).addToEnvironment("AppContext", appContext);

      instead of

      ((SimpleRuntimeEnvironment)environment).getEnvironmentTemplate().set("AppContext", appContext);

      inside the overridden adjustEnvironment method

      Delete
    14. Thank You,

      now it is working:)

      Delete
  6. Hello Maciej,
    I succeeded with one of the samples - spring boot starter basic but I am not able to deploy the BPM samples. saying unauthorized everytime. I am passing john:john1 as credentials and this is present in roles.properties.

    ReplyDelete
    Replies
    1. here are the default security config https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-spring-boot/kie-spring-boot-autoconfiguration/kie-server-spring-boot-autoconfiguration/src/main/java/org/kie/server/springboot/autoconfiguration/security/DefaultWebSecurityConfig.java#L45

      so make sure you either override it or use these that are in defaults.

      Delete
  7. Thanks Maciej. We are in critical phase in our project and we are using jbpm 7.6 embedded engine. We are facing issues and we require your help. Please let me know if you are available on slack to get immediate attention.

    While creating new process instance after deploying process, we are facing one error: EntityManager not closed. This is coming from Hibernate. I am using the ProcessDefController which you have created in one of the samples.

    Need your help.

    ReplyDelete
  8. Sorry.. In the above comment, please read the error as
    java.lang.IllegalStateException: EntityManager is closed. We are using Spring Boot starters. Able to successfully deploy bpm process but is failing while creating a new process instance

    ReplyDelete
    Replies
    1. make sure you use narayana 5.6.4 or later as it might be related to it as well.

      Delete
  9. Got it solved by adding spring.jpa.open-in-view=false.

    ReplyDelete
  10. Have one more question. Do you know how to configure a custom maven repository when using Spring boot starter basic embedded workflow engine? Our applications are deployed on docker container and we need to use nexus repository to deploy our workflow process. ANy idea how it can be achieved?

    ReplyDelete
    Replies
    1. this is no different than in any other setup, use settings.xml (standard way for maven) and place it either in ~/.m2/settings.xml or in any other location in your docker and then use system property kie.maven.settings.custom to point to that location

      Delete
  11. This comment has been removed by the author.

    ReplyDelete
  12. After using latest Spring boot starter, I am not able to boot up the Spring boot application. I am using SQL server with Narayana Transaction Manager. I am getting following error on startup. Please help. What could be the issue?

    Caused by: org.springframework.transaction.IllegalTransactionStateException: Transaction is already completed - do not call commit or rollback more than once per transaction
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:825) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.kie.spring.persistence.KieSpringTransactionManager.rollback(KieSpringTransactionManager.java:87) ~[kie-spring-7.6.0.Final.jar:7.6.0.Final]
    ... 62 common frames omitted

    ReplyDelete
  13. Hello Maciej,

    I need to start process with asynchronous tasks.
    I have process with script task that I've selected "Is Async" to true.
    I've also configured executor as follows:
    jbpm.executor.enabled=true
    jbpm.executor.retries=3
    jbpm.executor.interval=6
    jbpm.executor.threadPoolSize=1
    jbpm.executor.timeUnit=SECONDS
    When I run this process the job is put into the executor, but it is not starting, it just stays in queue.
    I'm checking the queue with service '/rest/server/jobs' and all jobs are QUEUED
    How could I run the jobs automatically?

    ReplyDelete
    Replies
    1. just tried this locally and it does work as expected, the only thing I changed was to set jbpm.executor.enabled to true and left other settings as defaults.

      try setting this to show more logging:
      logging.level.org.jbpm=DEBUG

      what version are you on?

      Delete
    2. The problem was connected with database.
      It did not work with H2 but it is working fine with PostgreSQL.
      I suppose there was conflict between some transactions.

      Delete
    3. Hello Maciej,

      there is one more problem with Async processes and Postgre database.
      I was getting error:
      =================
      2018-04-06 11:18:59.725 ERROR 14860 --- [0.1-8090-exec-3] o.k.s.remote.rest.jbpm.ProcessResource : Unexpected error during processing Could not rollback due to 'Unable to rollback transaction' rollback caused by Unable to commit transaction

      java.lang.RuntimeException: Could not rollback due to 'Unable to rollback transaction' rollback caused by Unable to commit transaction
      at org.drools.persistence.PersistableRunner.rollbackTransaction(PersistableRunner.java:420) ~[drools-persistence-jpa-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT]
      at org.drools.persistence.PersistableRunner.rollbackTransaction(PersistableRunner.java:403) ~[drools-persistence-jpa-7.7.0-SNAPSHOT.jar:7.7.0-SNAPSHOT]

      Caused by: org.postgresql.util.PSQLException: ERROR: prepared transactions are disabled
      Wskazówka: Set max_prepared_transactions to a nonzero value.
      ==========================
      Changing postgres configuration parameter max_prepared_transactions=100 resolved the problem, but is it necessary?

      Delete
    4. since it uses narayana which is complete XA transaction manager when it uses 2 phase commit so it then requires such setting

      Delete
  14. Hi Maceij,
    I posted this error earlier but have not any response. I am using Spring boot jbpm starter with SQL Server and I am getting following error on boot up. Please help resolve the issue.

    After using latest Spring boot starter, I am not able to boot up the Spring boot application. I am using SQL server with Narayana Transaction Manager. I am getting following error on startup. Please help. What could be the issue?

    Caused by: org.springframework.transaction.IllegalTransactionStateException: Transaction is already completed - do not call commit or rollback more than once per transaction
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:825) ~[spring-tx-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.kie.spring.persistence.KieSpringTransactionManager.rollback(KieSpringTransactionManager.java:87) ~[kie-spring-7.6.0.Final.jar:7.6.0.Final]
    ... 62 common frames omitted

    ReplyDelete
  15. Hello Maceij,
    I am using BPM Suite 6.4 is there a way to monitor, start, complete process and task that are deployed to a managed remote KIE execution server. I can deploy to that server but I cannot start processes instances and work on them.
    Thanks,
    Stathis P.

    ReplyDelete
    Replies
    1. I want to do this through business central. I know that I can build another UI to do this.

      Delete
    2. in v6 it's not possible. v6 uses embedded jbpm engine and thus requires all deployments to be in workbench. Workbench does not use kie server REST api for execution.

      Delete
  16. Hi Maciej,

    I run kie server using the distribution war files. I create a jbpm workflow using eclipse and deploy it as kjar in kie server using the workbench api. When I have a workflow which uses spring beans (derived through dependencies), the kie server doesn't load them and I end up getting NoSuchBeanDefinitionException. Is there a way to make spring based workflow work with kie-server?

    ReplyDelete