0
votes

I have following bean declaration xml.

  <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>

and Following is the code of 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

When I start the context I get following error

2017-06-01 06:50:22.625 GMT ERROR localhost-startStop-1 ContextLoader:331 - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.context.annotation.internalAsyncAnnotationProcessor': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.xxx.xxx.management.common.executor.TaskExecutorImpl' to required type 'java.util.concurrent.Executor' for property 'executor'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.xxx.xxx.management.common.executor.TaskExecutorImpl] to required type [java.util.concurrent.Executor] for property 'executor': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:529) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458) at 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.registerBeanPostProcessors(AbstractApplicationContext.java:743) at org.springvmframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:410) at 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(StandardContext.java:4853) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5314) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.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) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1092) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1834) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:748) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'com.messages.nsx.management.common.executor.TaskExecutorImpl' to required type 'java.util.concurrent.Executor' for property 'executor'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [com.xxx.xxx.management.common.executor.TaskExecutorImpl] to required type [java.util.concurrent.Executor] for property 'executor': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:464) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:495) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:489) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1465) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1424) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) ... 23 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [com.xxx.xxx.management.common.executor.TaskExecutorImpl] to required type [java.util.concurrent.Executor] for property 'executor': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:449) ... 29 more

1

1 Answers

0
votes

According to the stack trace that TaskExecutorImpl doesn't implement java.util.concurrent.Executor. And we really don't see that in the TaskExecutorImpl class.

It implements some TaskExecutor, but we can't say which one since there is no import for it. That only can say us that this interface is in the same package.

So, be sure that you implement the proper interface to meet that dependency injection requirements.