I need to send a email in async way while saving the data into DB.
My approach was like this.
//I have tried with service layer annotating.But not worked.
@EnableAsync
class MyService{
public String saveMethod(List listOfData){
mail.sendEmailQuote(listOfData);
mail.sendEmailWorkflowTaskAssignment(listOfData);
myDao.saveData(listOfData);
}
}
I need to perform following methods in @Async way. Where should I put @EnableAsync annotation. This is not a Schedule related thing. This is happen when user click save button. Application is used flex spring blazeDS. There is no controller written by my self.
I have used @Async annotation in my code for following 2 methods. Those are in class call Mail.
@Async
sendEmailQuote(listOfData){}
@Async
sendEmailWorkflowTaskAssignment(listOfData){}
Could you help me to find where should I put @EnableAsync ?
EnableAsyncis used for configuration and enable Spring's asynchronous method execution capability, it should not be put on yourServiceorComponentclass, it should be put on yourConfigurationclass like:Or with more configuration of your
AsyncExecutorlike:Please refer to it's java doc for more details.
And for the tutorial you followed,
EnableAsyncis put aboveApplicationclass, whichextends AsyncConfigurerSupportwith AsyncExecutor configuration: