我有 bean ,例如
<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() 实现接口(interface) MyInterface。
因此,管理器在服务对象上调用 init() 方法,如下所示:
private Set<MyService> services;
public void init() {
for (MyService service : services) {
service.init();
}
}
但是当bean初始化时我遇到以下问题:
Failed to convert property value of type 'java.util.LinkedHashSet' to required type 'java.util.Set' for property 'services'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.sun.proxy.$Proxy108 implementing com.MyInterface,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.MyService] for property 'services[0]': no matching editors or conversion strategy found.
最佳答案
您确定已发布所有配置吗?
因为周围有一些 AOP“隐藏”(可能是通过注释)代码,因为 service
bean 被代理。
你必须选择:
- 更改
private Set<MyService> services
的声明到“私有(private)设置服务” - 在 AOP 代码中让代理公开目标类 (
MyService
) 而不是接口(interface) (MyInterface
)
检查您的代码
关于java - spring bean 与 Set 属性相关的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22655085/