I have a simple class that has a property called “executor” in which I’d like to wire in an ExecutorService, with spring 3.0. I followed the documentation which states you simply use the factory class (in this case Executors) and supply factory-method to create your service. However, when I try to wire the resulting bean into my class, it seems that spring thinks the class type is java.lang.String instead of ExecutorService.
I have no idea what I’m doing wrong here. I seem to be correct if I look at the documentation, but perhaps I need to somehow indicate the resulting class of calling the factory method?
Here’s the error:
java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.concurrent.ExecutorService] for property ‘executor’: no matching editors or conversion strategy found
With this configuration:
<bean id="taskManager" class="examples.TaskManager">
<property name="executor">
<idref local="executorService" />
</property>
</bean>
<bean id="executorService" class="java.util.concurrent.Executors"
factory-method="newSingleThreadExecutor"
destroy-method="shutdownNow" />
and this class:
public class TaskManager {
private ExecutorService executor;
public ExecutorService getExecutor() {
return executor;
}
public void setExecutor(ExecutorService executor) {
this.executor = executor;
}
}
Try simple
refattribute instead ofidref:and see here that the meaning of
idrefis passing the referenced bean’s name (as aString) to the property.Oh, and here’s the Spring doc itself: