Karaf v2.3.0,org.apache.aries.blueprint.core:1.0.1,在从另一个包导入的服务上调用接口方法时抛出 ClassCastException。接口方法定义在接口上,由实现类实现。我无法弄清楚服务代理如何认为它是 Impl (TicketServiceImpl) 而不是接口 (TicketService)。我很感激有关如何解决此问题的任何建议或建议。
例外:
Caused by: java.lang.ClassCastException:
org.abc.TicketServiceImpl cannot be cast to
org.abc.TicketService at
Proxy3ac85313_c60c_42db_8def_ea7bd3d7411c.add(Unknown Source)
...
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.6.0_37]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)[:1.6.0_37]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)[:1.6.0_37]
at java.lang.reflect.Method.invoke(Method.java:597)[:1.6.0_37]
at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:297)[7:org.apache.aries.blueprint.core:1.0.1]
at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:958)[7:org.apache.aries.blueprint.core:1.0.1]
...
奇怪的是,在异常之前,我打印了代理 .getInterfaces(),这意味着代理是 TicketService,而不是 TicketServiceImpl。
MyTicketServer proxy interfaces: org.abc.TicketService,
org.apache.aries.proxy.weaving.WovenProxy
MyTicketServer Proxy class name: Proxy3ac85313_c60c_42db_8def_ea7bd3d7411c
我还尝试在代理上强制进行 Class 测试:
if (myTicketService instanceof TicketService) { <-- you'd think this would help
myTicketService.add(ticket); //<-- Throws proxy ClassCastException!!
} // implies problem is in the return path through proxy back to method