1. 程式人生 > >Cannot resolve reference to bean 'ItemCatService' while setting bean property 'ref'

Cannot resolve reference to bean 'ItemCatService' while setting bean property 'ref'

嚴重: Exceptionsending context initialized event to listener instance of classorg.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'cn.e3mall.service.ItemCatService': Cannotresolve reference to bean 'ItemCatService' while setting bean property 'ref';nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:No bean named 'ItemCatService' is defined

出現這個問題的原因有兩個

一:註解問題

在實現類中沒有加相應的註解。如dao層 @Repository  service @Service

web @Controller

二:配置檔案有問題

如果註解沒錯,那就是配置檔案有錯,要麼少寫了點什麼,要麼多寫了點什麼,好好檢查配置的路徑,大小寫字母

分享一下我犯的錯:

在我反反覆覆的檢查了註解之後,只能來查配置檔案

1.dubbo釋出服務的時候,applicationContext-service.xml配置檔案中itemCatServiceImpl這個單詞寫錯了


2.後來發現itemCatServiceImpl

類的名字寫成了itemCatServiceImp


為什麼寫錯這兩個地方就會出錯呢?

服務端的配置檔案applicationContext-service.xml用這段程式碼自動掃描


<context:component-scan base-package="cn.e3mall.service"></context:component-scan>

xml配置了<context:component-scan>這個標籤後,spring可以自動去掃描base-pack下面或者子包下面的java檔案,如果掃描到有@Component @[email protected]

等這些註解的類,則把這些類註冊為bean

dubbo和spring一塊使用,ref引用已存在的service服務(即已存在的spring bean物件),service才把已有的service服務釋出成dubbo服務

此段程式碼宣告需要暴露的服務介面,將服務釋出到註冊中心,消費者就可以用了


<dubbo:service interface="cn.e3mall.service.ItemService" ref="ItemServiceImpl" timeout="600000"/>

ref="ItemServiceImpl",這裡的ItemServiceImpl就是去找類ItemServiceImpl,這是一個約定,將 ref="XXX"中,將類XXX第一個字母小寫。

如果在此處不用自動掃描方法:

則需要自己配置bean

<bean id="itemService" class="cn.e3mall.service.impl.ItemServiceImpl"/>

<dubbo:service interface="cn.e3mall.service.ItemService" ref="itemService" timeout="600000"/>

這樣配置的話只需要將beanid的值和ref中的值相等就可以了

像我這樣,ref中的值和類名不對應,當然會報找不到bean的錯誤


相關推薦

Cannot resolve reference to bean 'ItemCatService' while setting bean property 'ref'

嚴重: Exceptionsending context initialized event to listener instance of classorg.springframework.web.context.ContextLoaderListener org.spr

Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref'錯誤總結

出現Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref' 這個錯誤一般是因為兩個原因 一、配置檔案原因 就是spring配置檔案,配置出現錯誤,如果是

Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref'錯誤總結

出現Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref' 這個錯誤一般是因為兩個原因 一、配置檔案原因 就是spring配置檔案,配置出現錯誤,

Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref'錯誤修改

Cannot resolve reference to bean 'searchItemServiceImpl' while setting bean property 'ref' 出現這個情況一般情況下是註解的問題,@Service我有多次沒有注入; 但今天是因為"se

Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument

spring 5.+jpa 配置類出錯: 十二月 20, 2018 5:53:01 下午 org.springframework.web.servlet.DispatcherServlet initServletBean嚴重: Context initialization failedorg.springf

@cannot lock ref 'HEAD': unable to resolve reference 'refs/heads/master': reference broken解決方法

@cannot lock ref ‘HEAD’: unable to resolve reference ‘refs/heads/master’: reference broken解決 修改了一小點東西打算commit,成功以後然後打算push,這時候悲劇發生了,我的垃圾電腦自動重啟了,

idea中applicationContext-trans.xml中的Cannot resolve bean 'dataSource'...的問題解決

問題如下: (applicationContext-trans.xml中的部分截圖) 先了解問題是怎麼出現的: 此處的dataSource是在applicationContext-dao.xml中配置的,如下: 本來是想直接引用過來,沒想到會出現無法解析的錯誤 問題解決: 原因是:因為sp

java 中的 Cannot make a static reference to the non-static method

原文: https://blog.csdn.net/q610376681/article/details/49359819   今天敲程式碼的時候遇到了這個問題,大體這個問題可以簡化成這樣; public class Test1 {     pu

java cannot make a static reference to the non-static method

我最後,還是無法理解和運用static, 這似乎太難. I am not able to understand what is wrong with my code. class Two { public static void main(String[] args) { in

Cannot make a static reference to the non-static method

本質上是一個“沒有例項化物件”的問題。 在靜態方法中,不能直接訪問非靜態成員(包括方法和變數)。因為,非靜態的變數是依賴於物件存在的,物件必須例項化之後,它的變數才會在記憶體中存在。例如一個類 Student 表示學生,它有一個變數String address。如果這個類沒有被例項化,則它的

JSON字串轉javabean-net.sf.ezmorph.bean.MorphDynaBean cannot be cast to java.util.Map

會報錯:MorphDynaBean cannot be cast to java.util.Map     在JSONObject.toBean的時候如果轉換的類中有集合,可以先定義Map<String, Class> classMap = new Hash

java.lang.ClassCastException: xxx.bean.XXX cannot be cast to xxx.bean.YYY

java.lang.ClassCastException: com.hahah.atcrowdfunding.bean.User cannot be cast to com.hahah.atcrowdfunding.bean.Role result寫錯了,應該是re

解決kylin報錯 ClassCastException org.apache.hadoop.hive.ql.exec.ConditionalTask cannot be cast to org.apache.hadoop.hive.ql.exec.mr.MapRedTask

conf lan exe hive oop ann 關於 .exe map 方法:去掉參數SET hive.auto.convert.join=true; 從配置文件$KYLIN_HOME/conf/kylin_hive_conf.xml刪掉 或 kylin-gui的cu

“無效數字” ;java.lang.Integer cannot be cast to java.lang.String

現在 類型 bsp 字段 ann 不難 esc ger ring 今天頁面上突然查詢不出數據,大致的sql語句是 select xx ,xxx from table a where a.lrmb in ( 6101060033, 6101

linux下開發,解決cocos2d-x中編譯出現的一個小問題, undefined reference to symbol &#39;pthread_create@@GLIBC_2.2.5&#39;

water span x86 code bject data- ace 技術分享 inux 解決cocos2d-x中編譯出現的一個小問題 對於cocos2d-x 2.×中編譯中,若頭文件裏引入了#include "cocos-ext.h",在進行C++編譯的時候會遇到例

org.slf4j.impl.Log4jLoggerAdapter cannot be cast to ch.qos.logback.classic.Logger

sock sso ring logger cat existing col classic con https://stackoverflow.com/questions/31433246/classcastexception-org-slf4j-impl-log4j

2類型轉換異常:Exception in thread "main" java.lang.ClassCastException:java.lang.Object cannot be cast to java.lang.Integer

cnblogs color pan rgs main string [] 類型 style public class TestException { public static void main(String[] args) { Object obj

[ c++] cmake 編譯時 undefined reference to `std::cout' 錯誤的解決方案

bin cut () cmake fin epo linking com urn cmake .. 和 make 之後,出現如下錯誤 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/Modu

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.String

protocol lang base arr ava ebs reat rac context 1、錯誤描寫敘述java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Str

org.apache.shiro.web.servlet.ShiroHttpServletRequest cannot be cast to org.springframwork.web.mult..

avi 時間 div col rac ext framwork 框架 報錯 在用dwz框架+spring MVC時上傳文件報的錯 詳細錯誤例如以下: 事實上就是一個類型轉換錯誤,但卻研究了好長時間,怎麽都不知道哪裏錯了。由於前面卸過一個文