项目启动报错怎么办?看看你Spring自动注入用对了嘛?@Autowired XxxService注入问题解决
2022-01-01 22:12
781 查看
问题
- 在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接口注入,同时注入了两个Bean
解决办法
- 在Service的实现类ServiceImpl上,使用 @Component或者 @Service注解将Service注入到Spring容器中
- 如果是使用Dubbo的SpringBoot项目,可以在Service实现类使用如下注解
@com.alibaba.dubbo.config.annotation.Service @org.springframework.stereotype.Service
- 注意: 要将Service实现类注入到容器,而不是Service接口
总结
- Spring容器注入规则
相关文章推荐
- 如何解决SpringBoot JpaRepository @Autowired 没法自动注入的问题
- spring + springmvc 项目中 @Autowired 自动转载失败问题及解决
- 解决SpringBoot项目@Autowired注入bean失败的问题
- activiti解决实现ExecutionListener spring 自动注入@Autowired为null问题
- servlet中利用spring的注解@Autowired自动注入service失败,优雅的解决方法
- springMVC项目启动时出现bean注入失败的情况:Error creating bean with name 'XXX': Injection of autowired dependencies
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案 标签: spring 201
- springMVC项目启动时出现bean注入失败的情况:Error creating bean with name 'XXX': Injection of autowired dependencies
- 解决SpringBoot项目使用多线程处理任务时无法通过@Autowired注入bean问题
- SpringBoot @AutowiredRestTemplate自动注入报:could not be found问题的理解和解决方案
- @resource或@Autowired Service service不能通过spring注入问题
- SpringBoot学习——@Autowired自动注入报:could not be found问题的理解和解决方案
- 关于Struts在Spring中使用autowired 自动注入的问题
- SpringBoot 多模块项目(module)Service自动注入(@Autowired)
- Spring 注解Autowired自动注入bean异常解决
- Spring Boot @Autowired 没法自动注入的问题
- Spring Boot @Autowired 没法自动注入的问题
- 关于Struts在Spring中使用autowired 自动注入的问题
- 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案
- 解决 SpringMvc 非controller类使用@Autowired注解 service注入为null的问题