PaulSH
2013-10-23 17:41
采纳率: 0%
浏览 341
已采纳

请教 SpringMVC 中 @Autowired 注入报错?

信息: Initializing Spring FrameworkServlet 'spring-mvc'
17:00:57,884 ERROR DispatcherServlet:457 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.sp.service.impl.UserServiceImpl com.sp.web.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.sp.service.impl.UserServiceImpl] 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.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • weixin_42501606 2013-10-23 18:02
    已采纳

    [code="java"]expected at least 1 bean which qualifies as autowire candidate for this dependency. [/code]

    提示的错误信息已经告诉你了。项目找不到你要自动注入的UserService.你看看你的扫描配置,对于需要扫描的package对了,应该是您的UserService所在的package不在扫面范围的package.

    点赞 打赏 评论

相关推荐 更多相似问题