Reputation: 566
I have bean e.g.
<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) is class which extends abstract class MyService with abstract method init() and implement interface MyInterface with method specificLogic().
So, manager calls method init() on service object like this:
private Set<MyService> services;
public void init() {
for (MyService service : services) {
service.init();
}
}
But I have following problem when bean is initializing:
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.
Upvotes: 0
Views: 1437
Reputation: 18383
Are you sure you have posted all your config?
Because there is some AOP "hidden" (maybe by annotations) code around because service
bean is proxied.
You have to choice:
private Set<MyService> services
to `private Set servicesMyService
) and not the interface (MyInterface
)Check your code
Upvotes: 1
Reputation: 932
Maybe you can try to initialize your Set services for the initialization.
You just declared it as
private Set<MyService> services;
It just considers the interface Set and in your bean configuration it seems like by default the set is a LinkedHashSet.
So you can try to initialize your Set services like :
private Set<MyService> services = new LinkedHashSet<>();
Upvotes: 0