失败我的春节,web应用注入Activiti的框架服务(failed to Inject Activ

2019-10-22 13:17发布

我试图创建使用框架的Activiti和Spring MVC我的web应用程序的工作流,所以我必须在applicationContext.xml文件注入Activiti的服务,然后自动装配这些服务。

这是一个JUnit测试后的CONSOL问题

坟墓捕捉到异常而TestExecutionListener的允许[org.springframework.test.context.support.DependencyInjectionTestExecutionListener@14c8743]准备测试实例[tds_erp.testSpring@144719c] org.springframework.beans.factory.BeanCreationException:错误创建名称为豆“tds_erp .testSpring“:自动装配依赖注入失败; 嵌套的例外是org.springframework.beans.factory.BeanCreationException:无法自动装配领域:org.activiti.engine.RepositoryService tds_erp.testSpring.repositoryService; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:无类型[org.activiti.engine.RepositoryService]的排位豆找到依赖性:预期至少1豆,其有资格作为自动装配候选这种依赖性。 依赖注解:{@ org.springframework.beans.factory.annotation.Autowired(所需=真)}

org.springframework.beans.factory.BeanCreationException:由造成无法自动装配领域:org.activiti.engine.RepositoryService tds_erp.testSpring.repositoryService; 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:无类型[org.activiti.engine.RepositoryService]的排位豆找到依赖性:预期至少1豆,其有资格作为自动装配候选这种依赖性。 依赖注解:{@ org.springframework.beans.factory.annotation.Autowired(所需=真)}

org.springframework.beans.factory.NoSuchBeanDefinitionException:通过引起[org.activiti.engine.RepositoryService]找到依赖性否类型的排位豆:预期至少1种豆,其有资格作为自动装配候选这种依赖性。 依赖注解:{@ org.springframework.beans.factory.annotation.Autowired(所需=真)}

applicatioContext.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"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        ">


    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy">
        <property name="targetDataSource">
            <bean class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
                <property name="driverClassName" value="com.mysql.jdbc.Driver" />
                <property name="url" value="jdbc:mysql://localhost:3306/activiti" />
                <property name="username" value="root" />
                <property name="password" value="admin" />
            </bean>
        </property>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
        <property name="databaseType" value="h2" />
        <property name="dataSource" ref="dataSource" />
        <property name="transactionManager" ref="transactionManager" />
        <property name="databaseSchemaUpdate" value="true" />
        <property name="deploymentResources"
            value="classpath*:chapter4/bookorder.spring.bpmn20.xml" />
        <property name="jobExecutorActivate" value="false" />
    </bean>
    <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
        <property name="processEngineConfiguration" ref="processEngineConfiguration" />
    </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" />
</beans>

JUnit测试文件:

import static org.junit.Assert.assertEquals;

import java.util.HashMap;
import java.util.Map;

import org.activiti.bpmn.model.Task;
import org.activiti.engine.FormService;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ManagementService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.spring.ProcessEngineFactoryBean;
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;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath*:applicatioContext.xml")

public class testSpring {

    @Autowired(required=true)
     RepositoryService repositoryService;
    @Autowired(required=true)
     RuntimeService runtimeService;
    @Autowired(required=true)
     TaskService taskService;


    @Test
    public void simpleSpringTest() {

    Map<String, Object> variableMap =
    new HashMap<String, Object>();
    variableMap.put("object", "Activiti in Action");
    variableMap.put("description", "123456");
    runtimeService.startProcessInstanceByKey(
    "employeeRequest", variableMap);

    Task task = (Task) taskService
    .createTaskQuery().taskAssignee("kermit")
    .singleResult();
    assertEquals("Complete order", task.getName());
    taskService.complete(task.getId());
    assertEquals(0, runtimeService.
    createProcessInstanceQuery().count());
    }
    }

请帮帮我 !

Answer 1:

它看起来像你想使用定义豆applicatioContext.xmlrepositoryService在您的测试情况等。 但是,你中声明the @ContextConfiguration是Activiti的默认配置文件activiti.cfg.xml你可以尝试在你的测试以下:

@ContextConfiguration("classpath:applicatioContext.xml")

只是一个建议:它可能是创建一个单独的一个好主意applicatioContext.xml为一个类似于在web应用上下文语境测试。 这将有助于保持不同的数据等,您可以管理比你的正常发育DB实例更好的数据的前/后置条件。 你甚至可以产卵的测试本身就是一个数据库实例和测试后拆除。

编辑:你可以给多个conf文件这样的- @ContextConfiguration(locations = { "classpath:applicatioContext.xml" , "classpath*:activiti.cfg.xml"}) 检查这个职位 。

通常限定“ <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration"> ”应该加载activiti.cfg.xml除非你已经改变其默认位置内部。



文章来源: failed to Inject Activiti framework services in my Spring webapp