hibernate-spring測試報錯:com.sun.proxy.$Proxy44 cannot be cast to com.mm.service.imp.RoleServic
錯誤內容
java.lang.ClassCastException: com.sun.proxy.$Proxy44 cannot be cast to com.mm.service.imp.RoleServiceImp
測試程式碼
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); RoleServiceImp bean = (RoleServiceImp) context.getBean("roleService"); Role r = new Role(); r.setName("超級管理員"); bean.save(r);
其中繼承關係,以及注入為:
@Service(value="roleService")
public class RoleServiceImp implements RoleService {...}
錯誤原因:通過context.getBean(“xxx”)獲取到的物件要轉為父介面型別
將程式碼改成如下即可:
ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml"); RoleService bean = (RoleService) context.getBean("roleService");
相關推薦
hibernate-spring測試報錯:com.sun.proxy.$Proxy44 cannot be cast to com.mm.service.imp.RoleServic
錯誤內容 java.lang.ClassCastException: com.sun.proxy.$Proxy44 cannot be cast to com.mm.service.imp.RoleServiceImp 測試程式碼 ApplicationContext conte
配置AOP時報錯:java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to
報錯: Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to ******** 看報錯資訊,顯示的是動態代理生成的類無法轉
動態代理異常com.sun.proxy.$Proxy0 cannot be cast to
本人在學習動態代理的時候,做了些練習,結果報出了 Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to異常; 與網上其他人寫的例子進行
java後臺接收json資料,報錯com.alibaba.fastjson.JSONObject cannot be cast to xxx
從前臺接收json封裝的list資料,在後臺接收時一直報錯,com.alibaba.fastjson.JSONObject cannot be cast to xxx, 使用這種方式接收可以接收 1 @RequestMapping(value = "/insertUser", method
部署CM報錯(7):hue無法訪問hbase報錯:HBase Thrift 1 server cannot be contacted: Could not connect to hadoop02:90
1.問題描述 cm安裝hue後,訪問hbase資料庫,報錯 HBase Thrift 1 server cannot be contacted: Could not connect to hadoop02:9090 2.問題原因 hbase的thrift server 1被關閉
ueditor百度富文字編輯器linux下報錯: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the file system
具體報錯資訊如下 java.io.FileNotFoundException: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the fi
webservice:com.sun.xml.bind.v2.runtime.JAXBContextImpl cannot be cast to com.sun.xml.internal.bind.a
用原生jdk開發好webservice服務端介面後,和客戶端聯調的過程中調不通,服務端報錯: java.lang.ExceptionInInitializerError at com.sun.xml.internal.ws.wsdl.PayloadQNameBasedO
探索RequestBody報com.alibaba.fastjson.JSONObject cannot be cast to xxx
rtu 資料 字符串數組 對象 list int 直接映射 結果 per 今天使用RequestBody接受前端傳過來的參數,以前接受字符串數組非常成功,這次把形參改成了List<User>,原本以為順利接受參數並映射成User的list結構,結果竟然在我取
springboot分頁條件查詢java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pageh
java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Page at com.boku.www.service.impl.Projec
java.util.LinkedHashMap cannot be cast to com.*** resetTemplate的GET請求返回值為帶泛型的型別
原因: resetTemplate的GET請求返回值為帶泛型的型別不可以直接使用,因為他內部封裝成了一個LinkedHashMap,所以我們直接用的時候就會報錯 解決:
分頁外掛不起效果java.lang.ClassCastException: java.util.ArrayList cannot be cast to com.github.pagehelper.Pa
錯誤程式碼 public List findUserPageFromMybatis(HttpServletRequest request, Integer pageNum, Integer pageSize) { pageNum = pageNum ==
spring單元測試報錯:萬用字元的匹配很全面, 但無法找到元素 'tx:advice' 的宣告。
報錯:Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 54 in XML document from class path resource [app
spring MVC 報錯:java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet
重新 chain http1 accesslog instance report ppc springmvc bstr 嚴重: Allocate exception for servlet SpringMVCjava.lang.ClassNotFoundExceptio
Spring Boot 報錯:Error creating bean with name 'entityManagerFactory' defined in class path resource
fine 依賴 debug isp jpa java idt .com ima spring boot 寫一個web項目,在使用spring-data-jpa的時候,啟動報如下錯誤: Error starting ApplicationContext. To display
Android studio執行單元測試報錯: Class Not Found: Empty Test Suite
使用Espresso時報錯 Class not found: “com.test.LoginUnitTest”Empty test suite. 原因:沒有將該測試類新增到InstrumentedTest中 解決: 1.開啟配置,選擇Edit Configurations
Spring Boot報錯:Whitelabel Error Page
今天在搭建Spring Boot專案的時候,在程式碼方面沒有任何錯誤的情況下,訪問頁面報了一個這樣的錯誤,一開始很費解,最後查閱文件,發現是因為我的Application啟動類的位置放錯了,一開始是這樣的: 但是當Application啟動的時候,Spring Boot會載入啟動類所在包下
部署Spring AOP報錯:org.springframework.beans.factory.BeanCreationException解決方法
在部署Spring AOP時出現如下錯誤: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminbean' defined in class path
單元測試報錯:unable to find a @SpringBootConfiguration
問題描述 今天做單元測試報錯:unable to find a @SpringBootConfiguration 問題原因 有幾種可能性,逐個排除下對症下藥: 1.程式入口類忘了新增:SpringBootApplication註解 2.程式入口類的包名和測試
Spring-MVC報錯:org.springframework.validation.BeanPropertyBindingResult
完成報錯如下: org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors Field error in object ‘
javaJunit單元測試報錯:Test is not an annotation type
今天寫一個小demo是用到單元測試,但是當我在方法上加上@Test的時候報錯:Test is not an annotation type 最後發現是因為我的同一個包裡面有一個叫做Test的類,衝突了。把Test類改個名字或者刪掉,問題解決。