spring 注入bean类型不匹配

查看:124
本文介绍了spring 注入bean类型不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

报错SEVERE: Error building bean
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.sendi.console.action.MainAction': Unsatisfied dependency expressed through bean property 'session': : Error creating bean with name 'activityAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sendi.console.service.ActivityService com.sendi.console.action.ActivityAction.activityService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.sendi.console.service.ActivityService] found for dependency: expected a

查了是注入bean类型不匹配,要哪里和哪匹配?

解决方案

Class

import com.test.bean.ServiceBean;
public class Action{
      @Autowired
      private ServiceBean serviceBean;
}

spring.xml

<bean id="serviceBean" class="com.test.bean.ServiceBean"/>

这里的两个serviceBean需要同一种类型

这篇关于spring 注入bean类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆