我有一堂课:
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时,应该(在调用此方法之前)启动拦截器。
似乎它忽略了拦截器。
为什么这不起作用?我做错了什么?
最佳答案
请公开您的方法,私有方法将不会被拦截。