Spring boot. How to Create TaskExecutor with Annotation?

Add a @Bean method to your Spring Boot application class:

@SpringBootApplication
@EnableAsync
public class MySpringBootApp {

    @Bean
    public TaskExecutor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(25);
        return executor;
    }

    public static void main(String[] args) {
        // ...
    }
}

See Java-based container configuration in the Spring Framework reference documentation on how to configure Spring using Java config instead of XML.

(Note: You don’t need to add @Configuration to the class because @SpringBootApplication already includes @Configuration).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)