我在做什麼錯當@Asynch
方法@Service
獨立Spring Boot應用程序中的註釋類不會異步運行?Spring中的@Async在Service類中不起作用?
當我運行它時,直接從主類(@SpringBootApplication
註釋)在作品中直接相同的方法。例如:
主類
@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 cal downloadAnSave() via downloadAllImages() it does not run asynchronously...
}
}
和我服務類(這裏異步行爲不工作):從同一個類中
@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) {
//
}
}
[控制器中的Spring Boot @Async方法正在同步執行]的可能副本(http://stackoverflow.com/questions/29284008/spring-boot-async-method-in-controller-is-executing-synchronously) – g00glen00b
問題本身似乎並不完全重複,但同樣的答案(和評論)適用於此。 – g00glen00b