回顾:
新建一个Activiti工程:
activiti.cfg.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!--
流程引擎配置对象的bean
-->
<bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
<property name="dataSource" ref="dataSource"></property>
<property name="transactionManager" ref="txManager"></property>
<property name="databaseSchemaUpdate" value="true"></property>
</bean>
<bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
<property name="processEngineConfiguration" ref="processEngineConfiguration"></property>
</bean>
<!--
获取服务接口的bean
-->
<bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService"></bean>
<bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService"></bean>
<bean id="taskService" factory-bean="processEngine" factory-method="getTaskService"></bean>
</beans>
beans.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:component-scan base-package="com.rl"/>
<import resource="classpath:activiti.cfg.xml"/>
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<property name="url" value="jdbc:mysql://localhost:3306/activiti_spring"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
</beans>
FlowService接口:
package com.rl.service;
public interface FlowService {
public void deploy();
}
FlowServiceImpl实现类:
package com.rl.service.impl;
import org.activiti.engine.RepositoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.rl.service.FlowService;
@Service
public class FlowServiceImpl implements FlowService {
@Autowired
RepositoryService repositoryService;
@Override
public void deploy() {
}
}
测试代码:
package com.rl.test;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.rl.service.FlowService;
public class ActivitiTest {
@Test
public void test() {
ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
FlowService fs = (FlowService) ctx.getBean("flowServiceImpl");
}
}
或者
package com.rl.test;
import org.activiti.engine.RepositoryService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.rl.service.FlowService;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:beans.xml")
public class ActivitiTest1 {
@Autowired
RepositoryService repositoryService;
@Autowired
FlowService flowService;
@Test
public void test() {
System.out.println(repositoryService);
System.out.println(flowService);
}
}