Java踩坑記錄-00001 BeanCreationException

異常描述

嚴重: 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&timestam
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或配置這個beanjava

出現該異常通常爲如下幾點:web

  • bean 沒有添加註解 或者註解的包引入錯誤
  • xml文件中,配置文件里路徑錯誤

解決方法

1.補全註解spring

@Component()
"對象的名稱"至關於bean標籤的id屬性,若是類不屬於javaEE三層架構中的任意一層,那麼使用就使用@Component
@Controller
通常用於表現層的註解。 做用和component
@Service
通常用於業務層的註解。 做用和component
@Repository
 通常用於持久層的註解。 做用和component


@Autowired
優先根據類型注入數據,若是有惟一的對象,那麼就能成功注入.若是沒有惟一的對象
那麼就自動根據變量名和ioc容器對象的名稱進行匹配,若是變量名稱都沒法對應上,那麼就報錯

@Reference
@Reference注入的是分佈式中的遠程服務對象  來自dubbo服務

2.查看xml是否正確架構

<dubbo:protocol name="dubbo" port="20884"/>
    
	<dubbo:application name="quasimodo-search-service"/>
    <dubbo:registry address="zookeeper://192.168.25.135:2181"/>
    <dubbo:annotation package="com.quasimodo.search.service.impl" />
相關文章
相關標籤/搜索