@Async
method in @Service
annotated class in standalone Spring Boot application doesn't run asynchronously. What am I doing wrong?
When I run the same method directly from main class (@SpringBootApplication
annotated), it works. Example:
Main class
@SpringBootApplication
@EnableAsync
public class Application implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
// here when I call downloadAnSave() it runs asynchronously...
// but when I call downloadAnSave() via downloadAllImages() it does not run asynchronously...
}
}
and my service class (and here asynchronous behavior doesn't work):
@EnableAsync
@Service
public class ImageProcessorService implements IIMageProcessorService {
public void downloadAllImages(Run lastRun) {
// this method calls downloadAnSave() in loop and should run asynchronously....
}
@Async
@Override
public boolean downloadAnSave(String productId, String imageUrl) {
//
}
}