您的位置:首页 > 编程语言 > Java开发

Spring boot @@Autowired注入空指针问题解决方案

2019-01-25 22:07 513 查看

出现情况: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之上,不然会有无数莫名其妙的问题出现。

 

 

  

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐