Setup a Spring Web Application Project

Now you are ready to set up your first process application project in Eclipse in the IDE of your choice, the following description uses Eclipse.

Set Up a Java Project

We will start by setting up a Spring web application as an Apache Maven Project inside Eclipse. This consists of four steps:

  1. Create a new Maven Project in Eclipse
  2. Add the Camunda & Spring framework dependencies
  3. Add the web.xml file for bootstrapping the Spring container
  4. Add a Spring application context XML configuration file

In the following sections, we go through this process step by step.

Create a new Maven Project in Eclipse

First, we set up a new Apache Maven based project in Eclipse. Let’s call it loanapproval-spring. The screenshot below illustrates the settings we choose. As we are deploying a web application, make sure to select Packaging: war.

When you are done, click Finish. Eclipse sets up a new Maven project. The project appears in the Project Explorer view.

Add Camunda BPM & Spring Framework Dependencies

The next step consists of setting up the Maven dependencies for the new project. Maven dependencies need to be added to the pom.xml file of the project. We add both the Camunda BPM and the Spring Framework dependencies:

<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>
  <groupId>org.camunda.bpm.getstarted</groupId>
  <artifactId>loanapproval-spring</artifactId>
  <version>0.1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <properties>
    <camunda.version>7.9.0</camunda.version>
    <spring.version>3.1.2.RELEASE</spring.version>
  </properties>

  <!-- import Camunda BOM to ensure correct versions of Camunda projects -->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-bom</artifactId>
        <version>${camunda.version}</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
    </dependency>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-spring</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId>
      <version>1.3.171</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.7.13</version>
    </dependency>
  </dependencies>

</project>

Add web.xml File for Bootstrapping the Spring Container

Next, we add a web.xml file for bootstrapping the spring container. In order to do so, first add a folder named WEB-INF to the (preexisting) src/main/webapp folder of your Maven project. Inside the src/main/webapp/WEB-INF folder, add a file named web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

</web-app>

Now you can perform the first build. Select the pom.xml in the Package Explorer, perform a right-click and select Run As / Maven Install

Add a Spring Application Context XML Configuration File

Next, we add a Spring ApplicationContext XML file to the same src/main/webapp/WEB-INF folder. The file must be named applicationContext.xml. We start with an empty file:

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

Congratulations, you have completed the project setup. Your project should now look as depicted in the screenshot to the left.

You can now perform a full Maven build and deploy the project to a vanilla Apache Tomcat server. You should see the following log output:

INFO org.apache.catalina.startup.HostConfig.deployWAR
Deploying web application archive ..\webapps\loanapproval-spring-0.1.0-SNAPSHOT.war
INFOorg.springframework.web.context.ContextLoader.initWebApplicationContext
Root WebApplicationContext: initialization started
INFO org.springframework.context.support.AbstractApplicationContext.prepareRefresh
Refreshing Root WebApplicationContext: startup date [DATE]; root of context hierarchy
INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions
Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
INFO org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons
Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@19930f2a: defining beans []; root of factory hierarchy
INFO org.springframework.web.context.ContextLoader.initWebApplicationContext
Root WebApplicationContext: initialization completed in 247 ms
INFO org.apache.catalina.startup.HostConfig.deployWAR
Deployment of web application archive ..\webapps\loanapproval-spring-0.1.0-SNAPSHOT.war has finished in 1,740 ms

This means that you have set up your Spring web application correctly.

Catch up: Get the Sources of Step-1.

Download as .zip or checkout the corresponding tag with Git.

You can checkout the current state from the GitHub repository.

If you have not cloned the repository yet, please execute the following command:

git clone https://github.com/camunda/camunda-get-started-spring.git

To checkout the current state of the process application please execute the following command:

git checkout -f Step-1
Or download as archive from here.

On this Page: