2013-10-10 34 views
0

時,我有一個bean定義爲:曖昧工廠方法的參數類型錯誤接線的ExecutorService的

<bean id="executor" class="java.util.concurrent.Executors" 
     factory-method="newSingleThreadExecutor" destroy-method="shutdownNow" /> 

當加載,這不幸的原因:

Ignoring factory method [public static java.util.concurrent.ExecutorService java.util.concurrent.Executors.newSingleThreadExecutor(java.util.concurrent.ThreadFactory)] of bean 'executor': 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'executor' defined in class path resource [main-config.xml]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.util.concurrent.ThreadFactory]: Ambiguous factory method argument types - did you specify the correct bean references as factory method arguments? 

春天似乎要使用的newSingleThreadExecutor( ThreadFactory)方法,而我只想使用無參數方法。任何想法爲什麼?

+0

我無法重現此錯誤。這對我來說可以。我在3.2.4上。你確定你正在發佈你正在使用的? –

回答

0

我不知道您使用的是哪個版本的彈簧,but every document for versions above 3.0 state爲靜態工廠方法提供參數,您需要在<bean>元素內使用<constructor-arg>

指定

<bean id="executor" class="java.util.concurrent.Executors" 
    factory-method="newSingleThreadExecutor" destroy-method="shutdownNow" /> 

將使用無參數方法newSingleThreadExeutor()