我有很多
Stateless
我的WildFly 10.2.0服务器上的beans。每次我尝试使用
@Interceptors({LogService.class})
它适用于任何方法,但适用于
@Schedule(second = "*/2", minute = "*", hour = "*")
这是我的拦截器类:
public class LogService {
@AroundInvoke
public Object interceptsAngLog(InvocationContext context) throws Exception {
Long millis = System.currentTimeMillis();
LocalTime now = new LocalTime();
Object object = context.proceed();
String method = context.getMethod().getName();
String className = context.getTarget().getClass().getName();
Long millisSpent = System.currentTimeMillis() - millis;
System.out.println("[LOG] " + now.toString() + "-" + className + "-" + method + ": " + millisSpent);
return object;
}
}
这是我的课程安排:
@Stateless
@Interceptors({LogService.class})
public class ScoreTimerService {
@EJB
private AccountDao accountDao;
@Schedule(second = "*/3", minute = "*", hour = "*")
public void addPointsDueOnlineState() {
List<Account> list = accountDao.findOnline();
for (Account account : list) {
account.addScore(5);
accountDao.update(account);
}
}
@Schedule(second = "*/2", minute = "*", hour = "*")
public void removePointsDueTime() {
List<Account> list = accountDao.findAll();
for (Account account : list) {
account.removeScore(1);
accountDao.update(account);
}
}
}
我尝试在方法、类和替换上使用
对于
@Interceptors(LogService.class)
但都没有奏效。