如何为 Spring AOP Aspect 提供超时执行?
MyAspect的记录器方法执行时间不应超过 30 秒,否则我想停止方法执行。我怎么能这样做?
我的方面代码:
@Aspect
@Component
public class MyAspect {
@Autowired
private myService myService;
@AfterReturning(pointcut = "execution(* xxxxx*(..))", returning = "paramOut")
public void logger(final JoinPoint jp, Object paramOut){
Event event = (Event) paramOut;
myService.save(event);
}
}
我的服务接口:
public interface myService {
void save(Event event);
}
myServiceImpl :
@Service
@Transactional
public class myServiceImpl implements myService {
@PersistenceContext
private EntityManager entityManager;
@Override
public void save(Event event) {
entityManager.persist(event);
}
}