开发者社区> 问答> 正文

一个activiti集成的问题,求助各位大神?报错

我新建了一个 ssm 想集成activiti设计器遇到问题,但是一直报错  说我的 repositoryService没有注入, 想求助于各位大神

首先是报错信息

aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.activiti.engine.RepositoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
	... 26 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.activiti.engine.RepositoryService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545)
	... 28 more

现在贴配置

1.首先是ModuleController

package lz.oa.activiti;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.activiti.editor.constants.ModelDataJsonConstants;
import org.activiti.engine.ManagementService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Model;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;

@Controller
@RequestMapping("/model")
public class ModuleController {

	private Logger logger = LoggerFactory.getLogger(ModuleController.class);
	@Autowired
	private RepositoryService repositoryService;
	@Autowired
	private RuntimeService runtimeService;
	@Autowired
	private TaskService taskService;
	@Autowired
	private ManagementService managementService;
	
	@RequestMapping(value = "/create")
	public void create(@RequestParam("name") String name, @RequestParam("key") String key,
	@RequestParam("description") String description, HttpServletRequest request, HttpServletResponse response) 
	{
		try {
			ObjectMapper objectMapper = new ObjectMapper();
			ObjectNode editorNode = objectMapper.createObjectNode();
			editorNode.put("id", "canvas");
			editorNode.put("resourceId", "canvas");
			ObjectNode stencilSetNode = objectMapper.createObjectNode();
			stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
			editorNode.put("stencilset", stencilSetNode);
			Model modelData = repositoryService.newModel();
			
			ObjectNode modelObjectNode = objectMapper.createObjectNode();
			modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
			modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
			description = StringUtils.defaultString(description);
			modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
			modelData.setMetaInfo(modelObjectNode.toString());
			modelData.setName(name);
			modelData.setKey(StringUtils.defaultString(key));
			
			repositoryService.saveModel(modelData);
			repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
			
			response.sendRedirect(request.getContextPath() + "/act/modeler.html?modelId=" + modelData.getId());
		} catch (Exception e) {
			logger.error("创建模型失败:", e);
		}
	}
}

2.然后是 activiti.cfg.xml

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

<!-- Activiti处理引擎的配置,交由Spring管理 -->
  <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 name="activityFontName"  value="宋体" />
      <property name="labelFontName"  value="宋体" />
      <property name="databaseType" value="oracle"/>
      <property name="processDefinitionCacheLimit" value="20"/>
  </bean>
  <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
   <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>
</beans>

3.spring-mvc.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:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                        http://www.springframework.org/schema/context
                        http://www.springframework.org/schema/context/spring-context-4.0.xsd
                        http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

	<context:annotation-config />
	
    <!-- 自动扫描  @Controller-->
	<context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
		<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> 
	</context:component-scan>
    <!--避免IE执行AJAX时,返回JSON出现下载文件 -->
    <bean id="mappingJacksonHttpMessageConverter"
          class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
        <property name="supportedMediaTypes">
            <list>
                <value>text/html;charset=UTF-8</value>
            </list>
        </property>
    </bean>
    <!-- 启动SpringMVC的注解功能,完成请求和注解POJO的映射 -->
    <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingJacksonHttpMessageConverter"/> <!-- JSON转换器 -->
            </list>
        </property>
    </bean>

    <!-- 定义跳转的文件的前后缀 ,视图模式配置 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/pages/" />
        <property name="suffix" value=".jsp"/>
    </bean>
	
	
    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- 默认编码 -->
        <property name="defaultEncoding" value="UTF-8"/>
        <!-- 上传文件大小限制为31M,31*1024*1024 -->
        <property name="maxUploadSize" value="32505856"/>
        <!-- 内存中的最大值 -->
        <property name="maxInMemorySize" value="4096"/>
    </bean>
    
</beans>

4.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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://www.springmodules.org/schema/cache/springmodules-cache.xsd http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name>oa</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring-mybatis.xml,classpath:activiti.cfg.xml</param-value>
  </context-param>
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <filter>
    <filter-name>contextFilter</filter-name>
    <filter-class>lz.oa.filter.ContextFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>contextFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <filter>
    <filter-name>encodingFilter</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>
  </filter>
  <filter-mapping>
    <filter-name>encodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <listener>
    <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
  </listener>
  
   
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.jpg</url-pattern>       
	</servlet-mapping>    
	<servlet-mapping>         
		<servlet-name>default</servlet-name>      
		<url-pattern>*.js</url-pattern>      
	</servlet-mapping>      
	<servlet-mapping>          
		<servlet-name>default</servlet-name>         
		<url-pattern>*.css</url-pattern>        
	</servlet-mapping>
	<servlet-mapping>          
		<servlet-name>default</servlet-name>         
		<url-pattern>*.png</url-pattern>        
	</servlet-mapping>
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.gif</url-pattern>       
	</servlet-mapping>  
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.html</url-pattern>       
	</servlet-mapping>
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.json</url-pattern>       
	</servlet-mapping> 
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.xml</url-pattern>       
	</servlet-mapping>
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.woff</url-pattern>       
	</servlet-mapping>
	<servlet-mapping>     
		<servlet-name>default</servlet-name>    
		<url-pattern>*.ttf</url-pattern>       
	</servlet-mapping>
  <servlet>
    <servlet-name>SpringMVC</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
  </servlet>
  <servlet-mapping>
    <servlet-name>SpringMVC</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>/login</welcome-file>
  </welcome-file-list>
  <session-config>
    <session-timeout>30</session-timeout>
  </session-config>
</web-app>

 

展开
收起
爱吃鱼的程序员 2020-06-06 10:55:10 2603 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
                        <p>报错信息头两行不是告诉你了吗</p> 
    

     

                        <p>aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService;</p> 
    

    <!-- 自动扫描 @Controller--> <context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">

     

    看起来是没扫private org.activiti.engine.RepositoryService ???

     

     

                        <div class="ref">
    

    引用来自“迹岸”的评论

    aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService;

    <!-- 自动扫描 @Controller--> <context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">

     

    看起来是没扫private org.activiti.engine.RepositoryService ???

     

     

                        <div class="ref">
    

    引用来自“TheBatMan”的评论

    引用来自“迹岸”的评论

    aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService;

    <!-- 自动扫描 @Controller--> <context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">

     

    看起来是没扫private org.activiti.engine.RepositoryService ???

     

     

    引用来自“迹岸”的评论

    引用来自“TheBatMan”的评论

    引用来自“迹岸”的评论

    aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService;

    <!-- 自动扫描 @Controller--> <context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">

     

    看起来是没扫private org.activiti.engine.RepositoryService ???

     

     

    引用来自“TheBatMan”的评论

    引用来自“迹岸”的评论

    引用来自“TheBatMan”的评论

    引用来自“迹岸”的评论

    aused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.activiti.engine.RepositoryService lz.oa.system.activiti.action.ModuleController.repositoryService;

    <!-- 自动扫描 @Controller--> <context:component-scan base-package="lz.oa, org.spring.activiti,org.spring.editer" use-default-filters="false">

     

    看起来是没扫private org.activiti.engine.RepositoryService ???

     

     

    手动在xml中定义activiti的几大服务对象
    2020-06-06 10:55:28
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里邮箱—安全高效集成 立即下载
集成智能接入网关APP:优化企业级移动办公网络 立即下载
云效助力企业集成安全到DevOps中 立即下载