Ich habe folgende Bean-Deklaration xml.Spring: Kann den Wert vom Typ TaskExecutorImpl in java.util.concurrent.Executor nicht konvertieren
<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>
und folgend ist der Code von 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
Wenn ich den Kontext beginne ich Fehler erhalten folgende
2017-06-01 06: 50: 22,625 GMT ERROR localhost-Start-Stopp-1 ContextLoader: 331 - Kontext-Initialisierung fehlgeschlagen org.springframework .beans.factory.BeanCreationException: Fehler beim Erstellen von Bean mit dem Namen 'org.springframework.context.annotation.internalAsyncAnnotationProcessor': Initialisierung von Bean fehlgeschlagen; geschachtelte Ausnahme ist org.springframework.beans.ConversionNotSupportedException: Fehler beim Konvertieren des Eigenschaftswerts vom Typ 'com.xxx.xxx.management.common.executor.TaskExecutorImpl' in den erforderlichen Typ 'java.util.concurrent.Executor' für die Eigenschaft 'executor' ; geschachtelte Ausnahme ist java.lang.IllegalStateException: Wert des Typs [com.xxx.xxx.management.common.executor.TaskExecutorImpl] kann nicht in den erforderlichen Typ [java.util.concurrent.Executor] für die Eigenschaft 'executor' konvertiert werden: keine übereinstimmenden Editoren oder Umwandlungsstrategie gefunden bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:529) bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java:458) bei org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject (AbstractBeanFactory.java:293) bei org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java:223) bei org.springframework.beans .factory.support.AbstractBeanFactory. doGetBean (AbstractBeanFactory.java:290) bei org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java:195) bei org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors (AbstractApplicationContext.java:743) bei org.springvmframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java:464) bei org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext (ContextLoader.java:410) bei org.springframework.web.context. ContextLoader.initWebApplicationContext (ContextLoader.java306) bei org.springframework.web.context.ContextLoaderListener.contextInitialized (ContextLoaderListener.java:112) bei org.apache.catalina.core.StandardContext.listenerStart (Stan dardContext.java:4853) bei org.apache.catalina.core.StandardContext.startInternal (StandardContext.java:5314) bei org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java:145) bei org. apache.catalina.core.ContainerBase.addChildInternal (ContainerBase.java:753) bei org.apache.catalina.core.ContainerBase.addChild (ContainerBase.java:729) bei org.apache.catalina.core.StandardHost.addChild (StandardHost.java:717) bei org.apache.catalina.startup.HostConfig.deployDirectory (HostConfig.java:1092) bei org.apache.catalina.startup.HostConfig $ DeployDirectory.run (HostConfig.java:1834) um java.util.concurrent.Executors $ RunnableAdapter.call (Executors.java:511) bei java.util.concurrent.FutureTask.run (FutureTask.jav a: 266) bei java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) bei java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java: 617) bei java.lang.Thread. run (Thread.java:748) Veranlasst von: org.springframework.beans.ConversionNotSupportedException: Fehler beim Konvertieren des Eigenschaftswerts vom Typ 'com.messages.nsx.management.common'.executor.TaskExecutorImpl 'zum erforderlichen Typ' java.util.concurrent.Executor 'für die Eigenschaft' executor '; geschachtelte Ausnahme ist java.lang.IllegalStateException: Wert des Typs [com.xxx.xxx.management.common.executor.TaskExecutorImpl] kann nicht in den erforderlichen Typ [java.util.concurrent.Executor] für die Eigenschaft 'executor' konvertiert werden: keine übereinstimmenden Editoren oder Wandlungsstrategie gefunden bei org.springframework.beans.BeanWrapperImpl.convertIfNecessary (BeanWrapperImpl.java:464) bei org.springframework.beans.BeanWrapperImpl.convertForProperty (BeanWrapperImpl.java:495) bei org.springframework.beans.BeanWrapperImpl. convertForProperty (BeanWrapperImpl.java:489) bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty (AbstractAutowireCapableBeanFactory.java:1465) bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues (AbstractAutowireCapableBeanFactory.java: 1424) bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean (AbstractAutowireCapableBeanFactory.java:1160) bei org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java:519) ... 23 mehr verursacht durch: java.lang.IllegalStateException: Wert des Typs [com.xxx.xxx.management.common.executor.TaskExecutorImpl] kann nicht in den erforderlichen Typ [java.util.concurrent.Executor] für die Eigenschaft 'executor' konvertiert werden: keine Übereinstimmung Strategie-Editoren oder Umwandlung gefunden bei org.springframework.beans.TypeConverterDelegate.convertIfNecessary (TypeConverterDelegate.java:267) bei org.springframework.beans.BeanWrapperImpl.convertIfNecessary (BeanWrapperImpl.java:449) ... 29 weitere
TaskExecutor ist eine einfache Schnittstelle. Executor ist eine Membervariable der konkreten Klasse. –
Nun, wenn diese Bean im Zusammenhang mit der asynchronen Infrastruktur im Spring-Kontext völlig unabhängig ist, sollten Sie erwägen, Ihren 'taskExecutor' in etwas anderes umzubenennen und' AsyncAnnotationPostProcessor' nicht zu verwechseln –