@ManagedProperty in a Spring managed bean is null
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>