问题
- 在Controller层应用 @Autowired注入Service时,提醒Bean中没有Service
-
在Service接口中应用 @Component注入后,启动我的项目问题提醒:
The web application [ROOT] appears to have started a thread named [DubboClientReconnectTimer-thread-2] but has failed to stop it. This is very likely to create a memory leak
起因
-
提醒Bean中没有Service:
- 因为没有将Service注入到Spring容器中,能够通过 @Component或者 @Service注解注入
-
在Service中应用注解注入到容器后,启动我的项目会报错:
- 因为在Service接口注入,同时注入了两个Bean
-
在Service接口注入,会将实现Service接口的子类也注入到容器中,所以会导致Dubbo重复性线程谬误
解决办法
- 在Service的实现类ServiceImpl上,应用 @Component或者 @Service注解将Service注入到Spring容器中
-
如果是应用Dubbo的SpringBoot我的项目,能够在Service实现类应用如下注解
@com.alibaba.dubbo.config.annotation.Service @org.springframework.stereotype.Service
-
留神: 要将Service实现类注入到容器,而不是Service接口
总结
- Spring容器注入规定
发表回复