如果我编写@managed bean批注并在faces-config.xml中定义它,那么bean会有两个实例吗? [英] Are there going to be two instances for a bean if I write @managed bean annotation and define same in faces-config.xml

查看:109
本文介绍了如果我编写@managed bean批注并在faces-config.xml中定义它,那么bean会有两个实例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序的某些地方,我们对Person bean和我们在faces-confing.xml中定义的同一Person bean使用@ManagedBean注释,如下所示.

In my application in some places we are using @ManagedBean annoation for Person bean and for the same Person bean we defining in the faces-confing.xml like below at the same time.

@ManagedBean("name=person")
 @SessionScoped
 Public class Person{


}

faces-config.xml

faces-config.xml

<managed-bean>
     <managed-bean-name>person</managed-bean-name>
     <managed-bean-class>com.test.sample.Person</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

我的问题是这种方法是否为Person bean创建两个实例,或者是否这样做?如果我对应用程序中的每个Bean进行此操作,都会对应用程序的性能产生影响吗?

my question is does this approach create two instances for the Person bean or it does matter if I do this? Does this have any effect on performance of my application If I do this for every Bean in my application?

推荐答案

为此情况定义了一个优先级. @ManagedBean注释避免了必须在faces-config.xml中配置条目,但是,如果两者都存在,则<managed-bean>条目将覆盖注释.

There's a priority defined for this case. @ManagedBean annotation avoids having to configure an entry in faces-config.xml but, if you have both, the <managed-bean> entry overrides the annotation.

在您的情况下,将仅配置一个与faces-config.xml条目类似的实例.在您的情况下,两种方法的配置方式相同,但是,您应该将faces-config.xml条目更改为类似

In your case, there'll be only one instance configured like your faces-config.xml entry. In your case, both approaches are configured the same way but, should you change your faces-config.xml entry to something like

<managed-bean>
     <managed-bean-name>personBean</managed-bean-name>
     <managed-bean-class>com.test.sample.Person</managed-bean-class>
     <managed-bean-scope>session</managed-bean-scope>
</managed-bean>

您的bean将在personBean(而不是person)下注册(这是注释定义的名称).

Your bean will be registered under personBean rather than person (which is the name defined by the annotation).

这篇关于如果我编写@managed bean批注并在faces-config.xml中定义它,那么bean会有两个实例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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