I did a @Service class in Spring Boot application with one of the methods that should run asynchronously. As I read method should be @Async annotat
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).