1
我正在使用使用spring框架的java web应用程序。 该应用程序有一个名为ServiceA类的类,如下所示。 而Interface1Impl实现了Interface1并扩展了Dao2类。 在Servicea.do()方法中,将x强制转换为Dao2会抛出异常,指出“无法将类型[$ Proxy1]的属性值转换为所需类型[Dao2]” 如何解决此问题,以便x可以转换为Dao2 ?谢谢。
public class ServiceA
{
private final Interface1 x; // injected
public ServiceA(Interface1 aInterface1Impl)
{
x = aInterface1Impl;
}
public string do()
{
// Exception: Failed to convert property value of type [$Proxy1]
// to required type [Dao2]
Dao2 dao = (Dao2)x;
return dao.run();
}
}
这里的局部弹簧配置文件
<bean id="dao-t" class="Interface1Impl">
<property name="ibatis" ref="ibatis-main"/>
</bean>
<bean id="proj" class="ServiceA">
<constructor-arg ref="dao-t"/>
</bean>