我的springboot应用程序中有一个场景,我将任务提交到线程池以进行异步执行。现在子执行中的一些方法是@AfterReturn的方面点建议的一部分。我观察到即使处理是异步完成的,我的主线程也会继续执行来自子线程的切入点建议,并且我的服务不会返回值,直到所有子线程完成执行。任何指针如何使建议在执行线程本身上运行?所以简而言之,控制器方法在dao方法执行及其对应的切入点执行之前是不会返回响应的。
@Controller
@RequestMapping(value = "/api")
public class SampleController {
@Autowired
SampleService service;
@RequestMapping(value = "/action", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@ResponseBody
public String action(@RequestBody String request){
service.action(request);
return "Success";
}
}
@Service
public class SampleService{
@Autowired
SampleDao dao;
@Async("threadPoolExecutor")
public void action(String request){
dao.action(request);
}
}
@Repository
public class SampleDao{
public void action(String request){
//do some db things
}
}
@Aspect
@Component
public class SampleAspect{
@AfterReturning(
pointcut = "execution( * com.sample.*.*.SampleDao.action(..))",
returning = "result")
public void audit(JoinPoint joinPoint, Object result) {
//dosome thing
}
}