Skip to main content

Camunda Spring Boot with Shared Engine with War file


This is the only one website (may be first) to show an example to create working war file for camunda shared engine using Spring Boot.

We analysed the problem using pure spring boot "starter" dependencies that it contains camunda engine plus tomcat, so even when you remove tomcat using either <provided> or <exclude>, it continues to run on tomcat as its already with in camunda engine. And when you try to create war file and paste in into shared camunda engine outside then that war will no work. This is because that war you created containing camunda engine and a tomcat inside it and when you paste into another outside camunda engine, it gets confused to which camunda to use.

Hence I worked on this and brought a mix version of spring and spring boot implementation of camunda.

So here you go....and thanks me later :)

Here is the pom file

--------------------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<project 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">
<modelVersion>4.0.0</modelVersion>

<artifactId>SmartInspector</artifactId>
<packaging>war</packaging>
<name>SmartInspector</name>
<description>Spring Boot Web JSP Camunda Smart Inspector</description>
<version>1.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>

<properties>
<java.version>1.8</java.version>

<camunda.version>7.11.0</camunda.version>
    <spring.version>4.3.24.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

</properties>

 <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-bom</artifactId>
        <version>${camunda.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-framework-bom</artifactId>
        <version>${spring.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-spring</artifactId>
    </dependency>
<dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
  </dependency>
<dependency>
         <groupId>org.apache.tomcat.embed</groupId>
         <artifactId>tomcat-embed-jasper</artifactId>
         <scope>provided</scope>
      </dependency>

<!-- Web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- Web with Tomcat + Embed -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

<!-- JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

<!-- Need this to compile JSP -->
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>

<!-- Need this to compile JSP -->
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>

<!-- Optional, for bootstrap -->
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7</version>
</dependency>
        
        <dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>

</dependencies>
<build>
<plugins>
<!-- Package as an executable jar/war -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>



Put this class to create war at the top:

package java4byte.camunda.;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootWebApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootWebApplication.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootWebApplication.class, args);
}

}







To get the camunda engine context into your projectm you need
to add the class in the same package as above..


import org.camunda.bpm.BpmPlatform;
import org.camunda.bpm.ProcessEngineService;
import org.camunda.bpm.engine.HistoryService;
import org.camunda.bpm.engine.ManagementService;
import org.camunda.bpm.engine.ProcessEngine;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.TaskService;
import org.camunda.bpm.engine.spring.application.SpringProcessApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;





@Configuration
@EnableWebMvc
@ComponentScan
public class MyApplicationContext extends WebMvcConfigurerAdapter {

 @Override
public void configureViewResolvers(ViewResolverRegistry registry) {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/jsp/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
registry.viewResolver(resolver);
}
    
    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
    }
    
            
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
  @Bean
  public ProcessEngineService processEngineService() {
    return BpmPlatform.getProcessEngineService();
  }

  @Bean(destroyMethod = "")
  public ProcessEngine processEngine(){
    return BpmPlatform.getDefaultProcessEngine();
  }

  @Bean
  public SpringProcessApplication processApplication()
  {
    return new SpringProcessApplication();
  }

  @Bean
  public RepositoryService repositoryService(ProcessEngine processEngine) {
    return processEngine.getRepositoryService();
  }

  @Bean
  public RuntimeService runtimeService(ProcessEngine processEngine) {
    return processEngine.getRuntimeService();
  }

  @Bean
  public TaskService taskService(ProcessEngine processEngine) {
    return processEngine.getTaskService();
  }

  @Bean
  public HistoryService historyService(ProcessEngine processEngine) {
    return processEngine.getHistoryService();
  }

  @Bean
  public ManagementService managementService(ProcessEngine processEngine) {
    return processEngine.getManagementService();
  }
  

}

Please see the git hub link https://github.com/Prittz/SpringBoot-Camunda-war







Comments

  1. would be great if you could upload your project to github repo somewhere. Sounds like I am having similar issue, not sure I am following your directions correctly.

    ReplyDelete
    Replies
    1. Hey sure i will provide the github link soon. Can you let me know what issue you are getting?

      Delete
    2. please try this
      https://github.com/Prittz/SpringBoot-Camunda-war

      Delete
  2. Hi Frds ,

    I used the same steps , finally while pushing war on weblogic , i am getting error like
    weblogic.application.ModuleException: java.lang.ClassNotFoundException: org.camunda.bpm.engine.rest.impl.FetchAndLockContextListener
    at weblogic.application.internal.ExtensibleModuleWrapper.prepare(ExtensibleModuleWrapper.java:114)
    =========================================
    Then :
    <Unable to set the activation state to true for the application "camunda-webapp-ee-wls-7.12.0-ee".
    weblogic.application.ModuleException: Module null can not be activated, not in ACTIVATED state: NEW
    at weblogic.diagnostics.module.WLDFModule.activate(WLDFModule.java:328)
    ========================================
    Finally :
    weblogic.application.ModuleException: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'runtimeService' defined in class path resource [org/camunda/bpm/engine/spring/SpringProcessEngineServicesConfiguration.class]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.camunda.bpm.engine.spring.SpringProcessEngineServicesConfiguration; factoryMethodName=getRuntimeService; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/camunda/bpm/engine/spring/SpringProcessEngineServicesConfiguration.class]] for bean 'runtimeService': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=camundaConfig; factoryMethodName=runtimeService; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [com/att/comet/config/CamundaConfig.class]] bound.
    at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)

    Let me now how can i resolved this ?

    ReplyDelete
    Replies
    1. For that error you must include the following line on your application.properties file:

      spring.main.allow-bean-definition-overriding=true

      Delete

Post a Comment

Popular posts from this blog

Java Signature Certificate

Signature A valid digital signature gives a recipient reason to believe that the message was created by a known sender ( authentication ), that the sender cannot deny having sent the message ( non-repudiation ), and that the message was not altered in transit ( integrity )   Original-data.getByte() + private key à signature All are in byte array As signature has to be passed through network, we convert into string but we cant use just string of original byte array because of security. Hence we do manipulation of byte array and convert into a different string. We shoud not send new String(byte [] signature) , we should send   new String(Base64.encode(byte[] signature)) Verification: Client send (new data + signature) object{ User name: Ram Id : 678 Signature : ZTngSmnSpmWIj40r5TQ1hmec0UbfJLSCRSxbVBxCwchcFu6A8RS+O9BUFgG7U+UozVlrO5xGl9tARHxcIK4y2x/UHvhfYu74SOq22XgdGNuPMGQ560pUpiSkXspfGuFh9xHqovNGs7MQvWyESgurqehdsFD18sXV0z7gnqqFm78= }

Stream flatMap() in Java with examples

Stream flatMap() in Java with examples Stream flatMap(Function mapper) returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element. Stream flatMap(Function mapper) is an  intermediate operation . These operations are always lazy. Intermediate operations are invoked on a Stream instance and after they finish their processing, they give a Stream instance as output. Note :  Each mapped stream is closed after its contents have been placed into this stream. If a mapped stream is null, an empty stream is used, instead. flatMap() V/s map()  : 1) map() takes a Stream and transform it to another Stream. It applies a function on each element of Stream and store return value into new Stream. It does not flatten the stream. But flatMap() is the combination of a map and a flat operation i.e, it applies a function to elements as well as flatten them. 2) map() is used for