当前位置: 代码迷 >> 综合 >> 遇见Error creating bean with name '控制器名字'的错误的时候怎么办
  详细解决方案

遇见Error creating bean with name '控制器名字'的错误的时候怎么办

热度:7   发布时间:2023-12-05 14:18:47.0

遇见这种问题,八成的可能性是找不到业务实现层,通过在业务实现层查找是否添加@Service注解。

Caused by: 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 'com.boron.service.UserService' available: expected at least 1 bean which qualifies as autowire candidate.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

原因:service层没有加注解
在搭spring mvc框架时,ide不会报错但会有编译错误的几个注意事项:
1.controller 加注解
@RestController
@RequestMapping("/user")

2.service加注解

@Service
@Autowired
3.dao 加注解和实现接口
@Param("")

  相关解决方案