我有以下bean聲明xml。Spring:無法將TaskExecutorImpl類型的值轉換爲java.util.concurrent.Executor
<bean id="taskExecutor" class="com.XXX.xxx.management.common.executor.TaskExecutorImpl"
destroy-method="shutdown">
<constructor-arg name="threadPoolSize" value="5"/>
<constructor-arg name="executionQueueCapacity" value="1000"/>
<constructor-arg name="typeLimit" value="5"/>
</bean>
以下是TaskExecutorImpl的代碼。
import java.util.AbstractQueue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.FutureTask;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;
import javax.annotation.PostConstruct;
public class TaskExecutorImpl implements TaskExecutor {
private final int threadPoolSize;
private final int executionQueueCapacity;
private final int typeLimit;
private BlockingPriorityTaskQueue executionQueue;
private ExecutorService threadPool;
private ConcurrentHashMap<String, AtomicInteger> executionByTypeMap = new ConcurrentHashMap<>();
/**
* Main lock guarding all access
*/
final ReentrantLock mainLock;
/**
* Condition for waiting takes
*/
private final Condition notEmpty;
/**
* Condition for waiting puts
*/
private final Condition notFull;
public TaskExecutorImpl(int threadPoolSize, int executionQueueCapacity, int typeLimit) {
this.threadPoolSize = threadPoolSize;
this.executionQueueCapacity = executionQueueCapacity;
this.typeLimit = typeLimit;
mainLock = new ReentrantLock();
notEmpty = mainLock.newCondition();
notFull = mainLock.newCondition();
}
@PostConstruct
@SuppressWarnings("unchecked")
public void initialize() {
executionQueue = new BlockingPriorityTaskQueue(executionQueueCapacity);
threadPool = new ThreadPoolExecutor(threadPoolSize, threadPoolSize, 0L, TimeUnit.MILLISECONDS,
(BlockingQueue) executionQueue);
// create core threads, required for type control
for (int i = 0; i < threadPoolSize; i++) {
threadPool.execute(new Runnable() {
@Override
public void run() {
// nothing here
}
});
}
}
and other Methdods implementation so on
當我開始我獲得以下錯誤上下文
2017年6月1日06:50:22.625 GMT ERROR本地主機-startStop-1的ContextLoader:331 - 上下文初始化失敗 org.springframework .beans.factory.BeanCreationException:使用名稱'org.springframework.context.annotation.internalAsyncAnnotationProcessor'創建bean時出錯:Bean初始化失敗;嵌套的異常是org.springframework.beans.ConversionNotSupportedException:未能將類型爲'com.xxx.xxx.management.common.executor.TaskExecutorImpl'的屬性值轉換爲屬性'executor'所需的類型'java.util.concurrent.Executor' ;嵌套異常是java.lang.IllegalStateException:無法將屬性'executor'的[com.xxx.xxx.management.common.executor.TaskExecutorImpl]類型的值轉換爲所需類型[java.util.concurrent.Executor]:沒有匹配的編輯器或轉換策略發現 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) 在org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:293) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223) at org.springframework.beans .factory.support.AbstractBeanFactory。 doGetBean(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessor(AbstractApplicationContext.java:743) 在org.springvmframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) 在org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) 在org.springframework.web.context。 ContextLoader.initWebApplicationContext(ContextLoader.java:306) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) at org.apache.catalina.core.StandardContext.listenerStart(Stan dardContext.java:4853) 在org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) 在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) 在有機apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729) at org.apache.catalina.core.StandardHost.addChild( StandardHost.java:717) 在org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1092) 在org.apache.catalina.startup.HostConfig $ DeployDirectory.run(HostConfig.java:1834) 在java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.jav (ThreadPoolExecutor.java:617) (java.lang.Thread)。運行(Thread.java:748) 原因:org.springframework.beans.ConversionNotSupportedException:未能轉換類型爲'com.messages.nsx.management.common的屬性值。executor.TaskExecutorImpl'爲屬性'executor'所需的類型'java.util.concurrent.Executor';嵌套異常是java.lang.IllegalStateException:無法將屬性'executor'的[com.xxx.xxx.management.common.executor.TaskExecutorImpl]類型的值轉換爲所需類型[java.util.concurrent.Executor]:沒有匹配的編輯器或轉換策略發現 在org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:464) 在org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:495) 在org.springframework.beans.BeanWrapperImpl。 convertForProperty(BeanWrapperImpl.java:489) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1465) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java: 1424) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ... 23個 引起:java.lang.IllegalStateException:無法將屬性'executor'的類型[com.xxx.xxx.management.common.executor.TaskExecutorImpl]的值轉換爲所需的類型[java.util.concurrent.Executor]:不匹配編輯或轉換戰略發現 在org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267) 在org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:449) ...... 29多個
TaskExecutor是一個簡單的界面。 Executor是具體類的成員變量。 –
那麼,如果這個bean與Spring上下文中的異步基礎設施完全無關,考慮將你的'taskExecutor'重命名爲別的東西不要混淆'AsyncAnnotationPostProcessor' –