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>