【发布时间】:2014-03-26 08:20:12
【问题描述】:
我有豆子,例如
<bean id="manager" class="com.Manager" init-method="init">
<property name="services">
<set>
<ref bean="service" />
</set>
</property>
</bean>
<bean id="myService"
class="com.MyService" abstract="true">
</bean>
<bean id="service" class="com.SpecificService" parent="myService">
</bean>
service(SpecificService) 是使用抽象方法 init() 扩展抽象类 MyService 的类 并使用方法 specificLogic() 实现接口 MyInterface。
因此,管理器在服务对象上调用方法 init(),如下所示:
private Set<MyService> services;
public void init() {
for (MyService service : services) {
service.init();
}
}
但是在 bean 初始化时我遇到了以下问题:
无法转换“java.util.LinkedHashSet”类型的属性值 属性“服务”所需的类型“java.util.Set”;嵌套异常是 java.lang.IllegalStateException: 无法将 [com.sun.proxy.$Proxy108 实现 com.MyInterface,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] 类型的值转换为所需类型 [ com.MyService] for property 'services[0]': 没有找到匹配的编辑器或转换策略。
【问题讨论】:
-
使用 util 命名空间并创建一个 util:set bean。参考link
-
是同样的问题。问题在于扩展抽象类并实现另一个接口。
-
这不是
Set和LinkedHashSet的问题。大约是com.MyInterface,org.springframework.aop.SpringProxy和com.MyService。向我们展示代码的 AOP 部分。 -
我没有 AOP 部分。