1

当我第一次访问我的页面时,页面使用的托管 bean 被实例化了两次(我在构造函数中通过了两次,具有相同的堆栈跟踪):

Daemon Thread [http-127.0.0.1-8080-1] (Suspended (breakpoint at line 76 in MyController))   
    MyController.<init>() line: 76  
    NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]   
    NativeConstructorAccessorImpl.newInstance(Object[]) line: 39    
    DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 27    
    Constructor<T>.newInstance(Object...) line: 513 
    Class<T>.newInstance0() line: 355   
    Class<T>.newInstance() line: 308    
    ManagedBeanBuilder(BeanBuilder).newBeanInstance() line: 186 
    ...
    pass throught two Filters (one of the filter uses Waffle and the other calls a web service...)  
    ...     
    Http11Protocol$Http11ConnectionHandler.process(Socket) line: 601    
    JIoEndpoint$Worker.run() line: 447  
    Thread.run() line: 662  

在 xhtml 中:

<a4j:keepAlive beanName="myController"></a4j:keepAlive>
<h:form>
...
</h:form>

在 faces-config.xml 中:

<managed-bean>
        <managed-bean-name>myController</managed-bean-name>
        <managed-bean-class>com.xx.MyController</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
</managed-bean>

为什么托管 bean 实例化两次?

谢谢你的想法...

使用

  • jsf 1.2
  • 富脸3.3.2.SR1

编辑:感谢Joeri Hendrickx,我发现我有两个不同的请求。所以新的问题是“为什么我在访问我的页面时有两个请求?”

4

1 回答 1

3

如果你得到一个请求范围的 bean 的两个实例,那应该意味着你有两个请求。

检查您的浏览器是否发送了两个请求(使用 firebug 或 fiddler)。如果它只发送一个,这意味着您的请求在堆栈中的某处重复(可能在过滤器中,甚至可能在自定义 servlet 中)。

于 2011-08-22T14:46:44.637 回答