繁体   English   中英

按下JSF命令按钮两次调用了Spring管理的请求范围的Bean构造函数

[英]Spring-managed request scoped bean constructor called twice on press of JSF command button

我正在使用JSF-Spring集成,我正在使用JSF <h:commandButton>从JSP调用Spring管理的请求范围的bean方法。 我不明白的一件事是,Spring bean的构造函数被调用了两次。 为什么会这样?

这是Spring托管的bean:

@org.springframework.stereotype.Component
@org.springframework.context.annotation.Scope("request")
public class MyAction implements java.io.Serializable {

    public MyAction(){
        System.out.println("inside request scoped bean");
    }

这是JSF视图:

<h:commandButton value="add" action="#{MyAction.add}" />

您可以调试以跟踪从何处调用构造函数吗? 可以肯定的是,其中一个调用正在尝试从其他地方初始化,另一个是从应用程序/ ui初始化

我得到了答案,由于Spring的cglib代理机制,构造函数被调用了两次。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM