java - 使用 Spring MVC 部署 Web 应用程序

标签 java web-applications spring-mvc war activiti

我以前从未遇到过这个问题。实际上,我有一个通过 war 文件运行的 Web 应用程序。我已经配置了 Spring 来使用它并且它工作得很好。

问题是我正在尝试通过 Spring 配置 Activiti。基本上,WEB-INF/processes 文件夹中有一组 .bpmn20.xml 文件。 Activiti 团队提到他们不知道如何在 Web 应用程序中配置它。作为独立应用程序,我可以自动部署资源 .bpmn20.xml 文件,因为进程文件夹位于类路径上。我在配置 Web 应用程序结构时遇到问题。

请看下面:

我创建了一个 Spring MVC 应用程序,并通过运行 DbSchemaCreate.main() 创建了一个 Activiti 数据库。实际上我的进程似乎没有部署在 war 文件上。当 Tomcat 启动时,ProcessEngine 通过 Spring 启动并工作。我可以访问 RuntimeService。代码如下:

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

未部署自动资源部署。我也尝试通过代码进行部署,但它抛出异常:

 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)

如何在网络应用程序中找到此资源?

我尝试将其放入 WEB-INF/processes/ProcessExample.bpmn20.xml 中。

我也尝试过:

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

编辑

这个网站可能有帮助,但我被困住了。

Is WEB-INF in the CLASSPATH?

最佳答案

也许尝试将定义流程的文件夹(您的 bpmn20.xml 文件)添加到构建路径

该错误告诉您,Activiti-Engine 无法找到您的文件,这就是为什么您需要告诉它在哪里可以找到它。

关于java - 使用 Spring MVC 部署 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12597912/

相关文章:

javascript - 单独的文件(HTML5、CSS 和 JS)

java - 为我的 webapp 自动添加 "www"子域

java - 从 Spring boot 加载多个 Angular 项目

spring - 在 SecurityContext 中找不到身份验证对象 - Spring 5

java - 更有效地从控制台读取 int 值

java - 为什么我们必须对不可变类进行防御性复制

java - 关于为什么使用 jsp :include tag into another jsp isn't working in this scenario? 传递对象的任何原因

java - 有关 Spring 转换器以及 Jaxb2RootElementHttpMessageConverter 如何在 Spring MVC 中工作的一些信息

java - 我怎样才能用红绿灯显示随机灯?

java - 在 JNI 中获取一个 int 数组