遇見Error creating bean with name '控制器名字'的錯誤的時候怎麼辦

遇見這種問題,八成的可能性是找不到業務實現層,通過在業務實現層查找是否添加@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("")

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章