简体   繁体   中英

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

I am using JSF-Spring integration, I am calling a Spring-managed request scoped bean method from the JSP using JSF <h:commandButton> . One thing I can't understand is that the constructor of the Spring bean is called twice. Why does this happen?

Here is the Spring managed 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");
    }

Here is the JSF view:

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

Can you debug to trace where the constructor is getting called from ? Pretty sure one of the calls is it is being tried to initialize from some other place and one from the application / ui

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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