Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
2012-10-08 01:33
471 查看
今天犯了一个很低级的错误,估计是写了一天的代码,头被整昏了吧,在此纪念一哈哈;
以下是整个程序的源码。
BrandDao
BrandDaoImpl
BrandService
BrandServiceImpl
大家应该都明白。
BrandService 是一个接口,目的.getBean("brandService")获取到的bean是BrandService的实现(也就是BrandServiceImpl),没想到我却去实现BrandDao了,也并没有报错,因为目前BrandDao和BrandService是一样的,所以导致类型转换错误,悲剧。警戒。。
以下是整个程序的源码。
public class BrandTest { private static ApplicationContext context; private static BrandService brandService; @BeforeClass public static void beforeClass(){ try { brandService = (BrandService) new ClassPathXmlApplicationContext("beans.xml").getBean("brandService"); } catch (BeansException e) { e.printStackTrace(); } } @Test public void testSave(){ brandService.save(new Brand("椰树瑜伽","/images/luoshu/gdgd.gif")); } }我的类结构还有:
BrandDao
BrandDaoImpl
BrandService
BrandServiceImpl
大家应该都明白。
BrandService 是一个接口,目的.getBean("brandService")获取到的bean是BrandService的实现(也就是BrandServiceImpl),没想到我却去实现BrandDao了,也并没有报错,因为目前BrandDao和BrandService是一样的,所以导致类型转换错误,悲剧。警戒。。
相关文章推荐
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- 解决spring使用动态代理类型转换失败的问题--java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...今天
- 解决spring使用动态代理类型转换失败的问题--java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...
- 解决spring使用动态代理类型转换失败的问题--java.lang.ClassCastException: com.sun.proxy.$Proxy$ cannot be cast to ...
- SSM整合时日期类型转换报错 java.lang.ClassCastException: org.springframework.web.servlet.support.JstlUtils$Sprin
- android ClassCastException 类型转换错误
- 奇怪的hibernate 的类型转换错误: java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang
- 关于Spring 事务错误 java.lang.ClassCastException: $Proxy0 cannot be cast
- Caused by: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer cannot be cast to javax.servlet.ServletContainerInitializer错误解决办法
- 关于使用动态代理创建代理对象是报错 java.lang.ClassCastException: $Proxy0 cannot be cast to 的解决办法
- spring boot集成tk.mybatis3.4.0通用mapper, java.lang.ClassCastException,实体不能转换为实体
- Dorado7保存时报转换错误 java.lang.ClassCastException: com.bstek.dorado.data.variant.Record cannot be cast to
- 当AOP代理遇上类型转换错误
- springboot devtools 嵌套jar 序列化错误 java.lang.ClassCastException 完美解决方案
- System.InvalidCastException: 无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Microsoft.Office.Interop.Word._Application”。
- oracle.sql.CLOB不能转换成oracle.sql.CLOB类型的异常 java.lang.ClassCastException: oracle.sql.CLOB
- hibernate命名查询时总是报类型转换异常:java.lang.ClassCastException
- 错误: java.lang.ClassCastException: org.springframework.web.SpringServletContainerInitializer c