不会调用具有@Named @ViewScoped的@PostConstruct拦截器 [英] @PostConstruct Interceptor with @Named @ViewScoped not invoked

查看:145
本文介绍了不会调用具有@Named @ViewScoped的@PostConstruct拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经仔细阅读了有关的文章Seam/Weld文档中的拦截器,并实现了InterceptorBinding:

I have read carefully the article about Interceptors in the Seam/Weld documentation and implemented a InterceptorBinding:

@InterceptorBinding
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
public @interface MyLog {}

Interceptor类:

@MyLog @Interceptor
public class ErpLogInterceptor implements Serializable
{
  @AroundInvoke
  public Object logMethodEntry(InvocationContext invocationContext) throws Exception
  {..}

  @PostConstruct
  public Object logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}
}

不,我尝试在@Named @ViewScoped bean中激活拦截器:

No I tried to activated the interceptor in the @Named @ViewScoped bean:

@javax.inject.Named;
@javax.faces.bean.ViewScoped
public class MyBean implements Serializable
{
  @PostConstruct @MyLog
  public void init()
  {...}

  @MyLog public void toggleButton()
  {..}
}

如果我按一下JSF页面上的按钮,则将正确地调用方法toggleButton ,并且会调用拦截器方法logMethodEntry.但是看来方法@PostConstruct(我感兴趣的)从来没有被我的班级拦截.

If I push a button on my JSF page the method toggleButton is invoked correctly and the Interceptor method logMethodEntry is called. But it seems the method @PostConstruct (I am interested in) is never intercepted by my class.

该问题似乎与 Java EE拦截器和@ViewScoped bean 有关,但实际上我的拦截器在 normal上工作方法.

The question seems to be related to Java EE Interceptors and @ViewScoped bean but actually my interceptor is working in normal methods.

推荐答案

您应将@PostConstruct拦截器的返回类型设置为void而不是Object. 更改:

You should set return type of @PostConstruct interceptor to void not Object. Change:

  @PostConstruct
  public Object logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}

收件人:

  @PostConstruct
  public void logPostConstruct(InvocationContext invocationContext) throws Exception
  {...}

这篇关于不会调用具有@Named @ViewScoped的@PostConstruct拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆