拦截器未在方法级别上调用

时间:2017-03-17 06:19:05

标签: java ejb interceptor

我有一个方法拦截器。拦截器位于一个单独的类中,它也已在beans.xml文件中定义,并在方法级别使用它。但它没有被调用。我的代码如下:

拦截班:

public class HttpPostInterceptorTest {

@AroundInvoke
public Object intercept(InvocationContext context) throws Exception {
    Object result = null;
    HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
    HttpServletResponse httpServletResponse = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
    if(httpServletRequest.getMethod().equals("GET")){
        //Business Logic
    }else{
        result = context.proceed();
    }

    return result;
}

在方法级别:

@Interceptors(HttpPostInterceptorTest.class)
@Transactional
public String save() {
    //Business Logic
    return null;
}

0 个答案:

没有答案