参考官网:Process Engine 配置 | docs.camunda.org
一 POM
注意:
1 低版本c3p0会报错:Method com/mchange/v2/c3p0/impl/NewProxyResultSet.isClosed()Z
千万记得要删除Target包下的旧版本!!!
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.4</version>
</dependency>
2 低版本jackson会报错:com.fasterxml.jackson.databind.exc.InvalidDefinitionException<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
3 如果先前创建过Camunda会报错:HistoryLevel mismatch删除Camunda,重新创建
4 springmvc4 中 web.xml配置的Log4jConfigListener
在springmvc5中已经弃用,所以需要修改
参考:spring5.0解决Log4jConfigListener过期问题_dabaishaflyw的博客-CSDN博客
<?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"> <parent> <artifactId>abc.parent</artifactId> <groupId>com.abc</groupId> <version>0.0.1-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>abc.webApprove</artifactId> <packaging>war</packaging> <name>abc.webApprove Maven Webapp</name> <!-- FIXME change it to the project's website --> <url>http://www.example.com</url> <properties> <camunda.version>7.17.0</camunda.version> <spring.version>5.3.18</spring.version> <h2.version>2.0.206</h2.version> <slf4j.version>1.7.36</slf4j.version> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>com.abc</groupId> <artifactId>abc.web</artifactId> </dependency> <!-- JPA --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.4.12.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-entitymanager</artifactId> <version>5.4.12.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <version>5.4.12.Final</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.11.13.RELEASE</version> </dependency> <!-- JPA --> <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-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version>0.9.5.4</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.9.8</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-web</artifactId> <version>2.9.1</version> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency> </dependencies> <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> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <uriEncoding>utf8</uriEncoding> <port>9007</port> <path>/</path> </configuration> </plugin> </plugins> <testResources> <!--test测试时可以使用man/resources下的pro配置文件--> <testResource> <directory>${project.basedir}/src/test/resources</directory> </testResource> <testResource> <directory>${project.basedir}/src/main/resources</directory> </testResource> </testResources> </build> </project>
二 web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <display-name>webApprove</display-name> <description>审批系统</description> <context-param> <param-name>webAppRootKey</param-name> <param-value>webApprove.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jRefreshInterval</param-name> <param-value>6000</param-value> </context-param> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext.xml</param-value> </context-param> <!-- log4j2-begin --> <listener> <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> </listener> <filter> <filter-name>log4jServletFilter</filter-name> <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class> </filter> <filter-mapping> <filter-name>log4jServletFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <!-- log4j2-end --> <listener> <description>spring监听器</description> <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <listener> <description>防止内存泄露</description> <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class> </listener> <listener> <listener-class> org.springframework.web.context.request.RequestContextListener </listener-class> </listener> <filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>setBasePathFilter</filter-name> <filter-class>com.abc.web.filter.SetBasePathFilter</filter-class> </filter> <filter-mapping> <filter-name>setBasePathFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <filter> <filter-name>checkSessionFilter</filter-name> <filter-class>com.abc.web.filter.CheckSessionFilter</filter-class> <init-param> <param-name>excludeUrl</param-name> <param-value>.*(login|check|setCookie).do.*</param-value> </init-param> </filter> <filter-mapping> <filter-name>checkSessionFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter> <filter-name>hibernateFilter</filter-name> <filter-class>org.springframework.orm.hibernate5.support.OpenSessionInViewFilter</filter-class> <!-- <init-param> <param-name>excludeSuffixs</param-name> <param-value>js,css,jpg,gif</param-value> </init-param> <init-param> <param-name>singleSession</param-name> <param-value>true</param-value> </init-param> --> <init-param> <param-name>sessionFactoryBeanName</param-name> <param-value>sessionFactory</param-value> </init-param> </filter> <filter-mapping> <filter-name>hibernateFilter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <servlet> <servlet-name>webApprove</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc-servlet.xml</param-value> </init-param> <init-param> <param-name>detectAllHandlerExceptionResolvers</param-name> <param-value>false</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>webApprove</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <session-config> <session-timeout>120</session-timeout> <tracking-mode>COOKIE</tracking-mode> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
三 官网中配置了:
但我的datasource已经在application.xml中配置了。
所以此处注释了
package com.abc.webApprove.config; import org.camunda.bpm.engine.*; import org.camunda.bpm.engine.spring.ProcessEngineFactoryBean; import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DriverManagerDataSource; import org.springframework.transaction.PlatformTransactionManager; import javax.sql.DataSource; @Configuration public class LoanApplicationContext { // @Bean // public DataSource dataSource() { // DriverManagerDataSource dataSource = new DriverManagerDataSource(); // dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); // dataSource.setUrl("jdbc:mysql://ip/abc_camunda?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&autoReconnectForPools=true&noAccessToProcedureBodies=true\n"); // dataSource.setUsername(" "); // dataSource.setPassword(" "); // return dataSource; // } @Bean public PlatformTransactionManager transactionManager(DataSource dataSource) { return new DataSourceTransactionManager(dataSource); } @Bean public SpringProcessEngineConfiguration engineConfiguration(DataSource dataSource, PlatformTransactionManager transactionManager) { SpringProcessEngineConfiguration configuration = new SpringProcessEngineConfiguration(); configuration.setProcessEngineName("engine"); configuration.setDataSource(dataSource); configuration.setTransactionManager(transactionManager); configuration.setDatabaseSchemaUpdate("true"); configuration.setJobExecutorActivate(false); return configuration; } @Bean public ProcessEngineFactoryBean engineFactory(SpringProcessEngineConfiguration engineConfiguration) { ProcessEngineFactoryBean factoryBean = new ProcessEngineFactoryBean(); factoryBean.setProcessEngineConfiguration(engineConfiguration); return factoryBean; } @Bean public ProcessEngine processEngine(ProcessEngineFactoryBean factoryBean) throws Exception { return factoryBean.getObject(); } @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(); } }
四 测试参考官网
因为bpmn文件发送比较麻烦,所以这里就不演示了。
标签:web,springmvc,spring,springframework,整合,org,camunda,com From: https://www.cnblogs.com/hanjun0612/p/16874702.html