使用spring 的@Autowired注解引起错误org.springframework.beans.factory.BeanCreationExceptio

tdy2837 2014-10-20 09:03:43
我要创建一个springmvc项目,使用了@Autowired注解引起下面的错误

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clothesController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.clothes.service.ClothesService com.clothes.controller.ClothesController.clothesService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}


Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.clothes.service.ClothesService com.clothes.controller.ClothesController.clothesService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}


Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}


2014-10-20 8:58:05 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet /product threw load() exception
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] 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)}



意思好像是ClothesService这个无法实例化,导致无法创建clothesController。

@Service("clothesService")
@Transactional
public class ClothesServiceImpl extends CommonServiceImpl implements ClothesService{

}

@Controller
@RequestMapping("/clothesController")
public class ClothesController {

private static final Logger logger=Logger.getLogger(ClothesController.class);

@Autowired
private ClothesService clothesService;

private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

@RequestMapping(params = "clothes")
public String toMainPage(){

return "main/index";
}

}

网上查资料,说要再配置文件中加
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
我也加上去了,现在不清楚问题出在哪里了,求解答。
...全文
38200 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2018-08-20
  • 打赏
  • 举报
回复 1

@Service("portalArticleService")
public class PortalArticleServiceImpl extends ArticleServiceImpl implements PortalArticleService{}




@Controller
@RequestMapping(value="/article")
@Scope("prototype")
public class ArticleController {
@Autowired
@Qualifier("portalArticleService")
private PortalArticleService portalArticleService;
}
街头小贩 2018-08-13
  • 打赏
  • 举报
回复
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.clothes.service.ClothesService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
re:
有重名的,spring无法确认你需要的到底是哪一个
luoboyutushen 2018-07-19
  • 打赏
  • 举报
回复
引用 4 楼 u011063194 的回复:
我也碰到这个问题,我还碰到注入了之后null


这个应该需要一个注入的工厂类 有可能是因为他的父类没有被spring管理 我们老师讲过的
qq_35451912 2016-12-06
  • 打赏
  • 举报
回复
实现类里面注解没加
奋斗龟 2016-11-24
  • 打赏
  • 举报
回复
你扫描包了吗? <context:component-scan base-package="com.gclc" />
qq314782718 2016-11-24
  • 打赏
  • 举报
回复
这个问题应该是接口的用实现类没有用@Service这个注解
u011063194 2015-01-29
  • 打赏
  • 举报
回复
我也碰到这个问题,我还碰到注入了之后null
tdy2837 2014-12-14
  • 打赏
  • 举报
回复
还没解决,这段时间没研究这个,如果有熟悉这个问题的朋友,请帮忙告知一下这是什么问题引起的,先谢谢啦。
xiao0lang 2014-11-12
  • 打赏
  • 举报
回复
帮顶 解决了吗 求方案!
tdy2837 2014-10-20
  • 打赏
  • 举报
回复
哪位能够帮帮忙呢,网上查一些类似的问题,但是仍然解决不了,求救。

10,612

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 其他
社区管理员
  • 其他
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧