How to add org.springframework.scheduling.concurrent to spring boot pom.xml file?

I have created a simple spring mvc application using spring-boot-starter-thymeleaf and STS. Now I want to add an asynchronous task and need to add org.springframework.scheduling.concurrent as a dependency. The exact error message is

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Please help me to figure out how to add the missing dependency.

My pom.xml is as follows:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.demo.demoweb</groupId>
<artifactId>demoweb</artifactId>
<version>0.1.0-SNAPSHOT</version>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>

    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>bootstrap</artifactId>
        <version>3.2.0</version>
    </dependency>
    <dependency>
        <groupId>org.webjars</groupId>
        <artifactId>jquery</artifactId>
        <version>2.1.1</version>
    </dependency>


</dependencies>

<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

Answers


You seem to have the dependency in place. All you need to do is to set up a bean for the ThreadPoolTaskExecutor. Example:

@Bean
public ThreadPoolTaskExecutor taskExecutor(){
    ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor();
    pool.setCorePoolSize(1);
    pool.setMaxPoolSize(10);
    pool.setWaitForTasksToCompleteOnShutdown(true);
    return pool;
}

Just add @EnableAsync annotation to your configuration to enable asynchronous methods.


Need Your Help

matplotlib issues when nan first in list

python graph matplotlib nan figure

I have two lists of numbers which I'm using matplotlib to graph in Python. However if one of the lists begins with the value of nan, matplotlib will not graph any of the 15k+ points I have. However...

Overlay div block with the image while AJAX loading

javascript jquery html css ajax

I know this is easy task and very common, but I cannot figure out how to do this ! It seems five minute task, but I have spent more than an hour... I am stupid I know.