【问题标题】:@Intertceptors does not work for web bean for JSF page@Intertceptors 不适用于 JSF 页面的 web bean
【发布时间】:2010-04-22 13:07:31
【问题描述】:
@Named
@ConversationScoped
@Interceptors(MyInterceptor.class)
public class BeanWeb implements Serializable {
    public String methodThrowException throws Exception() {
        throws new Exception();
    }
}

public class MyInterceptor {
    @AroundInvoke
    public Object intercept(InvocationContext ic) throws Exception {
        try {
            return ic.proceed();
        } catch (Exception e) {
            return null;
        }
    }
}

对于 @Stateless bean 拦截器有效,但对于 BeanWeb 拦截器无效。而且我们从来没有进入过“拦截”的方法。

  1. 为什么会这样?
  2. 如何拦截 BeanWeb 中的方法调用?

P.S.:所有这些都在 Glassfish 3.x 下进行。

【问题讨论】:

    标签: java jsf jakarta-ee


    【解决方案1】:

    成功了:

    @Named
    @Stateful
    @ConversationScoped
    @Interceptors(MyInterceptor.class)
    public class BeanWeb implements Serializable {
        public String methodThrowException throws Exception() {
            throws new Exception();
        }
    }
    
    public class MyInterceptor implements Serializable {
        @AroundInvoke
        public Object intercept(InvocationContext ic) throws Exception {
            try {
                return ic.proceed();
            } catch (Exception e) {
                return null;
            }
        }
    }
    

    我希望这是正确的。

    【讨论】:

      猜你喜欢
      • 2012-02-12
      • 2012-12-28
      • 1970-01-01
      • 2015-10-28
      • 2012-09-09
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 2015-11-16
      相关资源
      最近更新 更多