Announcement Announcement Module
Collapse
No announcement yet.
Jsf 2 annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jsf 2 annotations

    Hi,

    I'm trying to integrate Jsf2 (Mojarra 2.0.2) and Spring 3 (3.0.0). Everything is working fine, except for one detail.

    On my beans, annotated with @ManagedBean, when I try to use @Autowired to inject a service class I got null point exception.
    When I change @ManagedBean to @Controller the service is injected with no problems.

    Is there any incompatibility between spring and jsf 2 annotations or I'm missing something?

    Any thoughts?

  • #2
    Use the the forum search similair questions have been answered numerous times before.

    @Autowired only works for spring managed beans, JSF managed beans obviously aren't managed by spring.

    Comment


    • #3
      Add this line to WEB-INF/faces-config.xml:

      <el-resolver>org.springframework.web.jsf.el.SpringBean FacesELResolver</el-resolver>

      Comment


      • #4
        Asked because I was looking for a way to keep using the new jsf @ViewScoped and at the same time use the spring auto wire on my beans.

        With the @Controller or @Component I can't access this feature.

        Thanks

        Comment


        • #5
          Within the managed beans you don't use @Autowired in combination with @ManagedBean.

          Instead you use @ManagedProperty(value="#{nameOfTheSpringBean}")

          Comment


          • #6
            Originally posted by marcelo.borba View Post
            On my beans, annotated with @ManagedBean, when I try to use @Autowired to inject a service class I got null point exception.
            When I change @ManagedBean to @Controller the service is injected with no problems.
            It seems, you was using a wrong @ManagedBean annotation.
            Actually, there are two different intefaces with @ManagedBean annotation: javax.annotation.ManagedBean and javax.faces.bean.ManagedBean. So, in your code, apparently, has been used javax.faces.bean.ManagedBean
            while the need to use javax.annotation.ManagedBean.
            I decided to post the message in this thread, because I wasted a half a day, to find the cause of this problem.
            Good luck!

            Comment

            Working...
            X