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