@ManagedProperty in a Spring managed bean is null

*爱你&永不变心* 提交于 2019-11-27 14:31:46

Your JSF backing beans (MainBean and UserBean) should be managed either by JSF or by Spring, but not by both of them.

If your beans are managed by JSF:

  • You annotate them with @ManagedBean and @...Scoped
  • You don't need to declare them in applicationContext.xml
  • You use @ManagedProperty instead of @Autowired, even if you need to inject beans managed by Spring (don't forget setters, @ManagedProperty requires it):

    @ManagedProperty("#{userDao}")
    private UserDao userDao;
    

If your beans are managed by Spring:

  • You declare them in applicationContext.xml with appropriate scopes (view scope is not supported)
  • You don't need @ManagedBean and @...Scoped
  • You use @Autowired instead of @ManagedProperty and you cannot inject beans managed by JSF this way

In both cases you need to configure Spring-JSF bridge in faces-context.xml:

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