Java踩坑记录-00001 BeanCreationException

原文链接: https://my.oschina.net/u/4182917/blog/3089067

异常描述

严重: StandardWrapper.Throwable

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'itemSearchController' defined in file 
[C:\codespace\pinyougou-parent\pinyougou-search-web\target\classes\com\pinyougou\search\controller\ItemSearchController.class]: Initialization of bean failed; nested exception is 

org.springframework.beans.factory.BeanInitializationException:
Failed to init remote service reference at filed itemSearchService in class
com.pinyougou.search.controller.ItemSearchController; nested exception is
java.lang.IllegalStateException: Failed to check the status of the service

com.pinyougou.search.service.ItemSearchService. No provider available for the service
com.pinyougou.search.service.ItemSearchService from the url

zookeeper://192.168.25.135:2181/com.alibaba.dubbo.registry.RegistryService?application=pinyougou-search-web&dubbo=2.8.4&interface=com.pinyougou.search.service.
ItemSearchService&methods=search&pid=8600&revision=0.0.5-SNAPSHOT&side=consumer×tam
p=1565522609857 to the consumer 192.168.211.1 use dubbo version 2.8.4

异常原因

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

此为注入异常,bean没有实例到spring容器中,查看spring配置,有没有扫到这个bean或配置这个bean

出现该异常一般为以下几点:

  • bean 没有添加注解 或者注解的包引入错误
  • xml文件中,配置文件里路径错误

解决方法

1.补全注解

@Component()
"对象的名称"相当于bean标签的id属性,如果类不属于javaEE三层架构中的任意一层,那么使用就使用@Component
@Controller
一般用于表现层的注解。 作用和component
@Service
一般用于业务层的注解。 作用和component
@Repository
 一般用于持久层的注解。 作用和component


@Autowired
优先根据类型注入数据,如果有唯一的对象,那么就能成功注入.如果没有唯一的对象
那么就自动根据变量名和ioc容器对象的名称进行匹配,如果变量名称都无法对应上,那么就报错

@Reference
@Reference注入的是分布式中的远程服务对象  来自dubbo服务

2.查看xml是否正确

    
    
	
    
    

转载于:https://my.oschina.net/u/4182917/blog/3089067

你可能感兴趣的:(Java踩坑记录-00001 BeanCreationException)