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

前端 未结 1 1059
忘掉有多难
忘掉有多难 2020-12-21 14:31

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

相关标签:
1条回答
  • 2020-12-21 15:07

    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).

    0 讨论(0)
提交回复
热议问题