出现情况:repository controller service component
当发生controller中写入的dao可以正常注入,而service以及component中的@Autowired多般是因为在使用中没有注意调用的整体事件中都需要标记@Autowried,既是
@service/@component{
@Autowired
dao......(repository).........
}
@controller{
@Autowired
service........../component.......
}
还需要注意不要new service或者component。实例后会发生运行正常,但注入无法实例化导致的空指针。
需要注意,spring boot入口类必须放置在顶层,或者说在dao 和controller之上,不然会有无数莫名其妙的问题出现。