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
<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>
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?
There’s a priority defined for this case.
@ManagedBeanannotation avoids having to configure an entry infaces-config.xmlbut, 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.xmlentry. In your case, both approaches are configured the same way but, should you change yourfaces-config.xmlentry to something likeYour bean will be registered under
personBeanrather thanperson(which is the name defined by the annotation).