NoSuchMethodException when using Spring ThreadPoolTaskExecutor

Omer

I am using ThreadPoolTaskExecutor executor. It is defined in a spring bean. As guided in the documentation, the class has only 1 constructor which gets the TaskExecutor as a parameter.
When I am running the project as a standalone jar using ClassPathXmlApplicationContext, everything works correctly. The TaskExecutor is created and executed.
Now I wanted to connect the Jar project to my web application (war). I added the required dependency in my web application POM file and used some of the jar project code.
There are no compilation errors, and mvn package also passes. But when I start the server, I get the following error (full trace below):
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [me.somesome.task.SyncTaskPool]: No default constructor found; nested exception is java.lang.NoSuchMethodException: me. somesome.task.SyncTaskPool.()
The constructor that I have in the SyncTaskPool class is initiating the TaskExecutor. If I add a constructor with no arguments, the server starts and the empty constructor is executed (and not the parameterized constructor) I am using Spring 4.0.5.RELEASE In the jar application context the task executor is defined as:

<bean id="syncTaskPool" class="me.somesome.task.SyncTaskPool">
    <constructor-arg ref="myTaskExecutor" />
</bean>

The SyncTaskPool constructor:

package me.somesome.task;

import me.somesome.taskServiceFacade.ServiceFacade;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

@Component
public class SyncTaskPool  {    

    private static Logger logger = LogManager.getLogger(SyncTaskPool .class);

    // this field is being set by Spring. It is defined as a bean in the application context
    private TaskExecutor adTaskExecutor;

    @Autowired
    private ServiceFacade serviceFacade;

    public SyncTaskPool (TaskExecutor adTaskExecutor) {
        this.adTaskExecutor = adTaskExecutor;
    }

}

The full error:

2015-01-11T11:52:31,300 [localhost-startStop-1] _[1;31mERROR_[m org.springframework.web.context.ContextLoader.initWebApplicationContext - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adSyncTaskPool' defined in URL [jar:file:/C:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/ad-mgmt/WEB-INF/lib/component-stats-sync-impl2-0.0.1-SNAPSHOT.jar!/me/somesome/task/SyncTaskPool.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [me.somesome.task.SyncTaskPool]: No default constructor found; nested exception is java.lang.NoSuchMethodException: me.somesome.task.SyncTaskPool.<init>()
    at    org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4992) [catalina.jar:7.0.55]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5490) [catalina.jar:7.0.55]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.55]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) [catalina.jar:7.0.55]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) [catalina.jar:7.0.55]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_20]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_20]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_20]
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [me.somesome.task.SyncTaskPool]: No default constructor found; nested exception is java.lang.NoSuchMethodException: me.somesome.task.SyncTaskPool.<init>()
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:85) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    ... 22 more
Caused by: java.lang.NoSuchMethodException: me.somesome.task.SyncTaskPool.<init>()
    at java.lang.Class.getConstructor0(Class.java:3069) ~[?:1.8.0_20]
    at java.lang.Class.getDeclaredConstructor(Class.java:2165) ~[?:1.8.0_20]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:80) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069) ~[spring-beans-4.0.5.RELEASE.jar:4.0.5.RELEASE]
    ... 22 more

The jar application context:

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:sec="http://www.springframework.org/schema/security"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd"  >

    <context:annotation-config />

    <context:component-scan base-package="me.somesome" />
    <context:component-scan base-package="com.somesome" />

    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven />
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>

    <bean id="myTaskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor"> 
        <property name="corePoolSize" value="5" />
        <property name="maxPoolSize" value="10" />
        <property name="queueCapacity" value="25" />
    </bean>

    <bean id="syncTaskPool" class="me.somesome.task.SyncTaskPool">
        <constructor-arg ref="myTaskExecutor" />
    </bean> 

    <task:annotation-driven executor="myExecutor" scheduler="myScheduler"/>
    <task:executor id="myExecutor" pool-size="5"/>
    <task:scheduler id="myScheduler" pool-size="10"/>

    <bean id="catalogFacade" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl" value="http://127.0.0.1:6080/ad-mgmt/remoting/catalog" />
        <property name="serviceInterface" value="com.somesome.mgmt.facade.ICatalogFacade" />
        <property name="overloadEnabled" value="true" />
    </bean>

    <bean id="trackingAggregationService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
        <property name="serviceUrl" value="http://127.0.0.1:5080/tracking-manager2/remoting/trkmgr" />
        <property name="serviceInterface" value="me.somesome.track.trackingmanager.facade.TrackingManagerFacade" />
        <property name="overloadEnabled" value="true" />
    </bean>
</beans>

The War application context:

<?xml  version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:lang="http://www.springframework.org/schema/lang" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-   context.xsd
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
        http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <context:annotation-config />

    <context:component-scan base-package="com.somesome" />
    <context:component-scan base-package="me.somesome" />

    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="classpath:messages" />
        <property name="defaultEncoding" value="UTF-8" />
    </bean>
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
        p:location="/WEB-INF/jdbc.properties" />

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}" p:username="${jdbc.username}" p:password="${jdbc.password}" />

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">false</prop>
            </props>
        </property>
    </bean>

    <tx:annotation-driven />
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
</beans>
Omer

The problem was that the SyncTaskPool bean was defined twice. The first was Component annotation definition:

@Component
SyncTaskPool

The second was an xml definition:

<bean id="syncTaskPool" class="me.somesome.task.SyncTaskPool">
    <constructor-arg ref="myTaskExecutor" />
</bean>

I removed the Component annotation and I removed the autowired annotation from the SyncTaskPool definitions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

NoSuchMethodException when using Spring ThreadPoolTaskExecutor

From Dev

NoSuchMethodException when using reflection to instantiate protected constructor

From Dev

Spring ThreadPoolTaskScheduler vs ThreadPoolTaskExecutor

From Dev

Spring ThreadPoolTaskExecutor shutdown with Async task

From Dev

Multi Threaded Application with (Spring) ThreadPoolTaskExecutor

From Dev

Multi Threaded Application with (Spring) ThreadPoolTaskExecutor

From Dev

NoSuchMethodException when accessing method via reflection after using Proguard

From Dev

NoSuchMethodException when using reflection to get defineClass from ClassLoader

From Dev

Spring ThreadPoolTaskExecutor vs Java Executorservice cachedthreadpool

From Dev

How to create a different ThreadPoolTaskExecutor in Spring Boot?

From Dev

`ThreadPoolTaskExecutor` Threads are not killed after execution in Spring

From Dev

NoSuchMethodException when instantiating a generic class

From Dev

NoSuchMethodException when instantiating a generic class

From Dev

NoSuchMethodException when retrieve method by reflection

From Dev

NoSuchMethodException using the datastax cassandra mapper

From Dev

Spring Security Java NoSuchMethodException: SecurityConfig.<init>()

From Dev

Context initialization failed. Spring error NoSuchMethodException

From Dev

FirebaseRecyclerAdapter Give NoSuchMethodException If Build using Release Keystore

From Dev

When is it appropriate to cacheConsumers when using Spring CachingConnectionFactory?

From Dev

Using different packages for Controllers when using Spring

From Dev

Multipart file upload with Spring: NoSuchMethodException: ...CommonsMultipartFile.<init>()

From Dev

Getting NoSuchMethodException when running class despite method being in .class file

From Dev

NoSuchMethodException <init>() when extending javafx.scene.chart.LineChart

From Dev

Scala: NoSuchMethodException when invoking mutable.ArrayBuffer(List,Int)

From Dev

Custom cookie name when using Spring Session

From Dev

Spring Boot External Configuration when using Docker

From Dev

How to persist when using Spring Boot with JPA

From Java

Spring returns 404 when using MethodValidationPostProcessor

From Dev

How to close refcursor in spring when using simplejdbccall

Related Related

  1. 1

    NoSuchMethodException when using Spring ThreadPoolTaskExecutor

  2. 2

    NoSuchMethodException when using reflection to instantiate protected constructor

  3. 3

    Spring ThreadPoolTaskScheduler vs ThreadPoolTaskExecutor

  4. 4

    Spring ThreadPoolTaskExecutor shutdown with Async task

  5. 5

    Multi Threaded Application with (Spring) ThreadPoolTaskExecutor

  6. 6

    Multi Threaded Application with (Spring) ThreadPoolTaskExecutor

  7. 7

    NoSuchMethodException when accessing method via reflection after using Proguard

  8. 8

    NoSuchMethodException when using reflection to get defineClass from ClassLoader

  9. 9

    Spring ThreadPoolTaskExecutor vs Java Executorservice cachedthreadpool

  10. 10

    How to create a different ThreadPoolTaskExecutor in Spring Boot?

  11. 11

    `ThreadPoolTaskExecutor` Threads are not killed after execution in Spring

  12. 12

    NoSuchMethodException when instantiating a generic class

  13. 13

    NoSuchMethodException when instantiating a generic class

  14. 14

    NoSuchMethodException when retrieve method by reflection

  15. 15

    NoSuchMethodException using the datastax cassandra mapper

  16. 16

    Spring Security Java NoSuchMethodException: SecurityConfig.<init>()

  17. 17

    Context initialization failed. Spring error NoSuchMethodException

  18. 18

    FirebaseRecyclerAdapter Give NoSuchMethodException If Build using Release Keystore

  19. 19

    When is it appropriate to cacheConsumers when using Spring CachingConnectionFactory?

  20. 20

    Using different packages for Controllers when using Spring

  21. 21

    Multipart file upload with Spring: NoSuchMethodException: ...CommonsMultipartFile.<init>()

  22. 22

    Getting NoSuchMethodException when running class despite method being in .class file

  23. 23

    NoSuchMethodException <init>() when extending javafx.scene.chart.LineChart

  24. 24

    Scala: NoSuchMethodException when invoking mutable.ArrayBuffer(List,Int)

  25. 25

    Custom cookie name when using Spring Session

  26. 26

    Spring Boot External Configuration when using Docker

  27. 27

    How to persist when using Spring Boot with JPA

  28. 28

    Spring returns 404 when using MethodValidationPostProcessor

  29. 29

    How to close refcursor in spring when using simplejdbccall

HotTag

Archive