Activiti Building (ii) integration with spring

Source: Internet
Author: User

Reprint Please specify source address: http://www.cnblogs.com/lighten/p/5876773.html

This article mainly explains how to integrate the Activiti and spring frameworks, and then, over time, a basic demo will be placed on github, and the address will be given in the Activiti series guide article, if not given, because no build is complete (learning, update is slow). In accordance with the order of the construction of the text can also be built up.

The previous chapter will initialize the database and continue with the MAVEN project set up in that Chapter. Activiti and spring integration require the corresponding Jar packages, which will complement other Maven Dependencies:

<dependency><groupid>org.activiti</groupid><artifactid>activiti-spring</artifactid ><version>5.21.0</version></dependency><dependency><groupId> org.springframework</groupid><artifactid>spring-webmvc</artifactid><version>4.1.5. Release</version></dependency>

First configure the data source and create the Spring-db.xml file under src/main/resources, which is used to configure database related Matters:

<?xml version= "1.0" encoding= "UTF-8"? ><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 "><!--database Configuration File--><bean id=" Propertyconfigurer "class=" Org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">< Property Name= "locations" ><list><value>classpath:db.properties</value></list></ Property></bean><!--database connection Pool--><bean id= "dataSource" class= " Org.apache.commons.dbcp.BasicDataSource "destroy-method=" Close "><property name=" driverclassname "value=" ${ driverclassname} "/><property name=" url "value=" ${url} "/><property name=" username "value=" ${username} "/ ><property name= "password" value= "${password}"/></bean><!--database transaction Management--><bean id= " TransactionManager "class=" org.springframework.jdbc.DataSource. Datasourcetransactionmanager "><property name=" dataSource "><ref bean=" dataSource "/></property ></bean></beans>

Here the relevant parameters of the database into the file db.properties, and referenced in the xml, so convenient to modify, the path is still classpath, you can change, the corresponding configuration path is also Modified. The contents of the file are as Follows:

Driverclassname=com.mysql.jdbc.driverurl=jdbc:mysql://localhost:3306/activiti?usessl=falseusername= Rootpassword=root

Create the Spring-activiti.xml file under src/main/resources, which is used for the relevant configuration of the Activiti (optionally, it can be configured with code annotated), which reads as Follows:

<?xml version= "1.0" encoding= "UTF-8"? ><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 "><bean id=" processengineconfiguration "class= "org.activiti.spring.SpringProcessEngineConfiguration" ><property name= "dataSource" ><ref bean= " DataSource "/></property><property name=" transactionmanager "><ref bean=" TransactionManager "/ ></property><property name= "databasetype" value= "mysql" ></property><property name= " Databaseschemaupdate "value=" false "></property></bean><bean id=" Processengine "class=" Org.activiti.spring.ProcessEngineFactoryBean "><property name=" processengineconfiguration "ref=" Processengineconfiguration "></property></bean><!--7 kinds of services may not all Use--><bean id=" Repositoryservice "factory-bean=" ProceSsengine "factory-method=" getrepositoryservice "/><bean id=" runtimeservice "factory-bean=" processEngine " factory-method= "getruntimeservice"/><bean id= "formservice" factory-bean= "processengine" factory-method= " Getformservice "/><bean id=" identityservice "factory-bean=" processengine "factory-method=" getIdentityService "/><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 "/></beans>

finally, in classpath, Create a spring-app.xml, which is used for global configuration, to summarize all configurations. The content is as Follows:

<?xml version= "1.0" encoding= "UTF-8"? ><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 "><!--rollup Configuration--><import resource=" Classpath:spring-db.xml "/><import resource=" classpath:spring-activiti.xml "/></beans>

finally, Configure the related items in Src/main/webapp/web-inf/web.xml:

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "version=" 3.0 "><display-name>archetype Created Web Application </display-name><context-param><description>spring Global Configuration </description><param-name> contextconfiglocation</param-name><param-value>classpath:spring-app.xml</param-value></ Context-param><listener><listener-class>org.springframework.web.context.contextloaderlistener </listener-class></listener></web-app>

Then you can run up in Tomcat. This is just one of the most basic configuration options, and more detailed configuration and instructions will be explained later in one by One. The data source and transaction management can be changed to the configuration you want, or you can use ORM or jpa, which adds the appropriate configuration in the Bean with ID processengineconfiguration.

Activiti Building (ii) integration with spring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.