1

I have never come across this problem before. Actaully, I have a web application running through a war file. I have configured Spring to work with it and it works perfectly.

The problem is that I am trying to configure Activiti through Spring. Basically, there is a set of .bpmn20.xml files inside the WEB-INF/processes folder. The Activiti team has mentioned that they do not know how to configure this inside a web application. As a standlone application I can deploy resources .bpmn20.xml files automatically as the processes folder is on the classpath. I have having trouble configuring in a web application structure.

Please see below:

I am created a Spring MVC application and created an Activiti database by running the DbSchemaCreate.main(). Actaully my processes don't seem to deploy on the war file. When Tomcat starts the ProcessEngine is started through Spring and works. I can access the RuntimeService. The code can be seen below:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web- app_2_5.xsd"
   version="2.5">

   <display-name>WebApp</display-name>

   <context-param>
      <!-- Specifies the list of Spring Configuration files in comma separated format.-->
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring/activiti.xml
      </param-value>
   </context-param>

   <listener>
      <!-- Loads your Configuration Files-->
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
   </listener>

   <servlet>
      <servlet-name>example</servlet-name>
      <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>example</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>

   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>       

activiti.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans    http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
     <property name="dataSource" ref="dataSource"/>
     <property name="databaseSchemaUpdate" value="true"/>
     <property name="jobExecutorActivate" value="false"/>
     <property name="transactionManager" ref="transactionManager"></property>
     <!-- <propety name="beans">
        <map>
           <entry key="printer" value-ref="printer"/>
        </map>
        </property>-->
     <property name="deploymentResources" value="classpath*:/processes.*.bpmn20.xml"/>
  </bean>

  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
     <property name="processEngineConfiguration" ref="processEngineConfiguration"/>
  </bean>

  <bean id="dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
     <property name="driverClass" value="com.mysql.jdbc.Driver"/>
     <property name="url" value="jdbc:mysql://localhost:3306/activiti_example"/>
     <property name="username" value="root"/>
     <property name="password" value="password"/>
  </bean>

  <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
     <property name="dataSource" ref="dataSource"/>
  </bean>

  <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"/>

The automatic resosource deployment is not being deployed. I have also tried through the code to deploy but it throws an Exception:

 repositoryService.createDeployment().addClasspathResource("ProcessExample.bpmn20.xml").deploy();
 runtimeService.startProcessInstanceByKey("processExample", mapOfProcessVariables);

org.springframework.web.util.NestedServletException: Request processing failed; nested exception  is org.activiti.engine.ActivitiException: resource 'ProcessExample.bpmn20.xml' not found
   org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
   org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
root cause

  org.activiti.engine.ActivitiException: resource 'ProcessExample.bpmn20.xml' not found
  org.activiti.engine.impl.repository.DeploymentBuilderImpl.addClasspathResource   (DeploymentBuilderImpl.java:59)
  com.webchannel.web.EmailController.sendE(EController.java:46)
  sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  java.lang.reflect.Method.invoke(Method.java:597)
  org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
  org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
   org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
  org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
  org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
  org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
  org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

How can this resource be located inside the webapp?

I have tried putting it in WEB-INF/processes/ProcessExample.bpmn20.xml.

I have also tried:

<property name="deploymentResources" value="/WEB-INF/processes.*.bpmn20.xml"/>

EDIT

This website may help, but I am stuck.

Is WEB-INF in the CLASSPATH?

Community
  • 1
  • 1
user1646481
  • 1,267
  • 6
  • 21
  • 29

2 Answers2

1

Maybe try adding the folder where the process is defined (your bpmn20.xml file) to the build path.

The error tells you, that the Activiti-Engine cannot find your file, that's why you need to tell it where to find it.

Peter O.
  • 32,158
  • 14
  • 82
  • 96
Ioana
  • 59
  • 4
0

Try This :

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
   http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

 <!-- for specifies the Web application display name  --> 
 <display-name>APMC</display-name>
 
   <!-- For Authentication processing mechanisms -->
   <filter>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
    </filter>  
    <filter-mapping>  
        <filter-name>springSecurityFilterChain</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
  
   <!-- For mapping request resource and combine its results with the matching JSP -->
 <servlet>
    <servlet-name>mvc-dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring-security.xml
      </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  
 <servlet>
  <servlet-name>rest</servlet-name>
  <servlet-class>
    org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <load-on-startup>2</load-on-startup>
 </servlet>

 <servlet-mapping>
  <servlet-name>rest</servlet-name>
  <url-pattern>/rest/*</url-pattern>
 </servlet-mapping>
  
 <!-- ContextLoaderListener  provides access to the ServletContext  -->
 <context-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/spring-config.xml, 
          /WEB-INF/spring-security.xml
   </param-value>
 </context-param>
  <listener>
 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  
</web-app>
Above file is web.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:task="http://www.springframework.org/schema/task"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" 
 xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd
         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">
  
   <context:component-scan base-package="com.apmc.dao" />
   
 <context:component-scan base-package="com.apmc.services" />
 <task:annotation-driven executor="taskExecutor" scheduler="taskScheduler" />
    <task:executor id="taskExecutor" pool-size="1"  /> 
    <task:scheduler id="taskScheduler" pool-size="1"  />
    
 <context:component-scan base-package="com.apmc.controller" />
 <context:component-scan base-package="com.apmc.rest" />
   <context:property-placeholder location="classpath:database.properties" />
   <context:property-placeholder location="classpath:log4j.properties" />

 <mvc:resources mapping="/resources/**" location="/resources/mytheme/" />
 <mvc:annotation-driven />

 <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <property name="driverClassName" value="${database.driver}" />
  <property name="url" value="${database.url}" />
  <property name="username" value="${database.user}" />
  <property name="password" value="${database.password}" />
 </bean>
 
 <bean id="sessionFactory"
  class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
  <property name="dataSource" ref="dataSource" />
  <property name="annotatedClasses">  
            <list>  
                <value>com.apmc.domain.Vehicle</value>
            </list>  
        </property> 
        
  <property name="hibernateProperties">
   <props>
    <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
    <prop key="hibernate.format_sql">false</prop>
    <prop key="hibernate.use_sql_comments">false</prop>
   </props>
  </property>
  
 </bean>
 
 <bean id="txManager"
  class="org.springframework.orm.hibernate4.HibernateTransactionManager">
  <property name="sessionFactory" ref="sessionFactory" />
 </bean>
 
 <bean id="persistenceExceptionTranslationPostProcessor"
  class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />
   
 <bean
  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix">
   <value>/WEB-INF/pages/</value>
  </property>
  <property name="suffix">
   <value>.jsp</value>
  </property>
 </bean>
 
 <bean id="messageSource"
  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">

  <property name="basename" value="/WEB-INF/messages" />

 </bean>
 
 <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate">  
  <property name="sessionFactory" ref="sessionFactory" />
    </bean> 
    
</beans>

Above code is spring-config.xml

Add database.properties file in resources folder of src folder. So write code in database.properties

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/apmc_db
database.user=root
database.password=
hibernate.show_sql=true