0

I'm using Spring Boot 2.3.5.RELEASE and I noticed that @Async methods in my application are working without adding @EnableAsync in any configuration class.

After some digging, I saw a comment from Marten Deinum suggesting that adding spring-boot-starter-actuator can enable @Async and scheduling by default.

Does spring-boot-starter-actuator implicitly enable async support?

When I add @EnableAsync and run, I get a BeanCreationException.

@Configuration
public class AsyncConfig implements WebMvcConfigurer {

@Bean(name = "taskExecutor")
public AsyncTaskExecutor taskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(10);
executor.setMaxPoolSize(50);
executor.setQueueCapacity(500);
executor.setThreadNamePrefix("Async-");
executor.initialize();
return executor;
}

@Override
public void configureAsyncSupport(AsyncSupportConfigurer 
configurer) {
configurer.setTaskExecutor(taskExecutor());
}
}

@Service
public class TaskExecutorService {

@Async("taskExecutor")
public void sendEmailAndNotification(Candidate candidate) {
    // Your logic to send email and notification
}
}

this code work without error, but if I add @EnableAsync I get this,

Error

5
  • 2
    What's the exception? Commented Apr 9 at 10:03
  • Please provide enough code so others can better understand or reproduce the problem. Commented Apr 9 at 10:20
  • share Async method code, quite possible you are using the thread. if not then check your dependencies and find out which dependency is calling the EnableAsync implicitly. Commented Apr 9 at 13:26
  • Please don't add the stacktrace (partial even) as an image. Copy the full stacktrace as code in your question. Why does your configuration use WebMvcConfigurer, that is async support for the controllers and has nothing to do with @Async. You should use the AsyncConfigurer instead. Commented Apr 10 at 7:28
  • I have removed that part because it's previously implemented. What I want to know is why it works without @EnableAsync? That error comes when I run with this annotation. Commented Apr 10 at 9:55

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.