1
我的WildFly 10.2.0服務器上有大量的Stateless
豆子。每次嘗試使用@Interceptors({LogService.class})
時,它都可以使用任何方法,但只有2個@Schedule(second = "*/2", minute = "*", hour = "*")
方法的Stateless
bean除外。我查找了文檔,但沒有找到任何線索。誰能幫我?我使用的Java 8爲什麼我的攔截器類不適用於調度方法?
這裏是我的攔截器類:
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})
爲@Interceptors(LogService.class)
但沒有人工作。
ü可以分享一些代碼嗎? – Vahid
對不起,我剛剛加了 – GabrielRado
是你用javax.interceptor.Interceptors註解的嗎? – Vahid