私はWildFly 10.2.0サーバーに多くのStateless
豆を持っています。たびに私は@Interceptors({LogService.class})
を使用しようとすると、Stateless
のbeanが2つしかない@Schedule(second = "*/2", minute = "*", hour = "*")
のメソッドを除いて、どのメソッドでも動作します。私はドキュメンテーションを探しましたが、何か手掛かりが見つかりませんでした。誰でも助けてくれますか?私は私のインターセプタクラスがスケジュールメソッドで動作しないのはなぜですか?
はここに私のインターセプタクラスのJava 8を使用しています:@Interceptors(LogService.class)
ため@Interceptors({LogService.class})
を交換するには、
@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);
}
}
}
は、私はクラスに、メソッドに使用してみました:ここ
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;
}
}
とすることは、私のスケジュールクラスですどれも働いていません。
ために、魔法のように働いていましたか? – Vahid
申し訳ありませんが、 – GabrielRado
はjavax.interceptor.Interceptorsアノテーションを使用していますか? – Vahid