Are there going to be two instances for a bean if I write @managed bean annotation and define same in faces-config.xml

a 夏天 提交于 2019-11-29 15:38:03

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.

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>

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!