拦截器未调用且不可见(在日志中,在部署期间什么也看不到)
Interceptor is not invoking and not visible (in logs, during deployments nothing see)
我有一个类:
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
public class AccessReportInterceptor {
private Logger log = Logger.getLogger(AccessReportInterceptor.class);
@Inject
private AccessReportManager accessReportManager;
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
log.info("invoked");
return context.proceed();
}
}
@Stateless
@Remote(ActionTypeHandlerRemote.class)
public class ActionTypeHandler implements ActionTypeHandlerRemote{
@EJB protected DataManager dataManager;
@Interceptors({AccessReportInterceptor.class})
private void persistNewUser(User newUser){
logger.info("Persisting new user: " + newUser.getLogin());
logger.info("For : " + newUser.getName());
newUser.setCreateTime(new Date());
dataManager.persist(newUser);
}
@Interceptors({AccessReportInterceptor.class})
private void mergeUser(User user){
logger.info("Merging user with id: " + user.getLogin());
user.setCreateTime(new Date());
dataManager.merge(user);
}
}
当我调用方法 persistNewUser 或 mergeUser 时,应该(在调用此方法之前)启动拦截器。
好像忽略了Interceptor
为什么这不起作用?我做错了什么?
请让你的方法public,私有方法不会被拦截
我有一个类:
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
public class AccessReportInterceptor {
private Logger log = Logger.getLogger(AccessReportInterceptor.class);
@Inject
private AccessReportManager accessReportManager;
@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
log.info("invoked");
return context.proceed();
}
}
@Stateless
@Remote(ActionTypeHandlerRemote.class)
public class ActionTypeHandler implements ActionTypeHandlerRemote{
@EJB protected DataManager dataManager;
@Interceptors({AccessReportInterceptor.class})
private void persistNewUser(User newUser){
logger.info("Persisting new user: " + newUser.getLogin());
logger.info("For : " + newUser.getName());
newUser.setCreateTime(new Date());
dataManager.persist(newUser);
}
@Interceptors({AccessReportInterceptor.class})
private void mergeUser(User user){
logger.info("Merging user with id: " + user.getLogin());
user.setCreateTime(new Date());
dataManager.merge(user);
}
}
当我调用方法 persistNewUser 或 mergeUser 时,应该(在调用此方法之前)启动拦截器。
好像忽略了Interceptor
为什么这不起作用?我做错了什么?
请让你的方法public,私有方法不会被拦截