org.springframework.beans.factory.UnsatisfiedDependencyException

org.springframework.beans.factory.UnsatisfiedDependencyException
错误:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘userController’: Unsatisfied dependency expressed through field ‘userService’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘Service.UserService’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

原因:创建userController对象时,通过userService字段名无法获得满足的满足的以来关系,原因有:

  1. 在类中为书写@Service注解,使得配置文件无法根据bean id识别完成自动注入
  2. 在方法上未书写 @Autowired,又未写setter()和getter()方法

处理:知道报错提示的类或者接口,添加相应的注解