码迷,mamicode.com
首页 > 其他好文 > 详细

cannot be cast to

时间:2017-09-07 00:54:13      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:sch   intern   测试   contex   xpl   映射   child   list   dac   

java.lang.ClassCastException: com.service.impl.OrderPlanServiceImpl cannot be cast to com.provider.service.IUserInfoService
at com.easylabplus.provider.test.UserInfoTest.testUserInfoService(UserInfoTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

 问题提示没有在第二个类当中找到你注册的Service名字

原因是我的测试类中没有写好Service对应的映射名字

 1 @Test
 2     public void testUserInfoService() throws Exception {
 3         ClassPathXmlApplicationContext aContext = new ClassPathXmlApplicationContext(
 4                 "applicationContext.xml");
 5                 //问题就是下边这个userInfoService的名字写错了
 6         IUserInfoService userInfoService = (IUserInfoService) aContext
 7                 .getBean("userInfoService");
 8         List<UserInfo> list = userInfoService.queryAll();
 9         Gson g = new Gson();
10         System.out.println(g.toJson(list));
11 
12     }

 

cannot be cast to

标签:sch   intern   测试   contex   xpl   映射   child   list   dac   

原文地址:http://www.cnblogs.com/liuyangfirst/p/7487654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!