spring dubbo @Reference Caused by: java.lang.NullPointerException: null 空指针异常
springboot dubbo @Reference Caused by: java.lang.NullPointerException: null 空指针异常dubbo @Reference 空指针异常错误代码摘要原因处理方法dubbo @Reference 空指针异常错误代码摘要Caused by: org.springframework.beans.factory.BeanCreation
·
springboot dubbo @Reference Caused by: java.lang.NullPointerException: null 空指针异常
dubbo @Reference 空指针异常
错误代码摘要
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of @Reference dependencies is failed; nested exception is java.lang.NullPointerException
原因
报错时我也看了很多博客但始终解决不了问题,不是网上所长出现的原因,可以检查下是否是这个原因,因为我主动注入的bean,所以spring没有处理@Reference注解,导致引用的dubbo服务为空
注入bean
@Bean("PermissionsRealm")
public PermissionsRealm getPermissionsRealm() {
PermissionsRealm permissionsRealm = new PermissionsRealm();
return permissionsRealm;
}
PermissionsRealm中自动注入了UserService
@Autowired
private UserService userService;
UserService中使用了dubbo服务
@Reference(check = false)
GatewayService gatewayService;
处理方法
仔细检查下自己主动注入的bean是否有service中引入了dubbo服务,取消注入bean即可
public PermissionsRealm getPermissionsRealm() {
PermissionsRealm permissionsRealm = new PermissionsRealm();
return permissionsRealm;
}
修改后
2020-08-04 09:52:48 [restartedMain] INFO org.apache.coyote.http11.Http11NioProtocol -Starting ProtocolHandler ["http-nio-80"]
2020-08-04 09:52:48 [restartedMain] INFO org.springframework.boot.web.embedded.tomcat.TomcatWebServer -Tomcat started on port(s): 80 (http) with context path '/'
2020-08-04 09:52:48 [restartedMain] INFO com.scsoft.SpringbootSesamApplication -Started SpringbootSesamApplication in 11.001 seconds (JVM running for 11.923)
思路就是这样,自己变通即可
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)