PostConstruct被调用两次

时间:2014-01-15 18:17:39

标签: spring jsf postconstruct

我用,

  • JSF
  • 弹簧
  • OCPSoft重写
  • Glassfish 4 / Jetty 9

我注意到我的bean会两次调用@PostConstruct的{​​{1}}方法。这里是初始化两次的示例bean,如果你需要init()或其他任何东西,只需发布​​它 - 我的想法用完了。

web.xml

1 个答案:

答案 0 :(得分:2)

我们在这里遇到了这个问题,但是WebSphere 6存在问题。(从websphere失控:D)

所以...我们做了一些解决方法来使用@PostConstruct ...
也许可以帮到你...

public boolean firstInit() {
    boolean firstInit= false;
        try {
            FacesContext context = FacesContext.getCurrentInstance();
            firstInit= context != null  && context.getExternalContext().getRequestParameterMap().containsKey(ResponseStateManager.VIEW_STATE_PARAM);
        } catch (Exception e) {
            firstInit= false;
        }
        return firstInit;
    }
public void init(){
if (firstInit()) return;
//init methods
}

@PostConstruct method called twice for the same request这也可以帮到你......

obs:我不能写评论:/

相关问题