首页 > 代码库 > org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut

spring中一个符号的错误居然让我浪费了四五个小时才找出来,不得不给自己了两个耳光。。

由于新建项目与原来项目的目录结构有所不同,copy过来的配置文件,有些地方修改的不彻底,导致spring扫描注解的时候,扫描不到,不能注入bean,导致运行出错。
一个马虎浪费了这么多时间,符号这种问题也往往最容易忽视的。
<context:component-scan base-package="com.oskyhang.*.service"/>

<context:component-scan base-package="com.oskyhang.*.service.*"/>

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut