0

I´m starting my Bean when the application starts with the following Bean:

...
@ManagedBean(eager = true)
@ApplicationScoped
public class LoadBean implements Serializable {
...

It Works as expected, the problem is (I suppose) that dependencies used inside my Bean are not initialized. They are null when I´m going to use them.

...
    @ManagedProperty("#{pservice}")
    Pservice pservice

    @PostConstruct
    public void init() { 
        ...
        pservice.doSomething()    // Null pointer exception
        ...
    }

    public void setPservice(Pservice pservice) {
        this.pservice = pservice;
    }
...

How could I handle this? Is there a way to force the execution of the Bean when are the dependencies are ready? Thanks in advance

juanmorschrott
  • 573
  • 5
  • 25
  • Where is `pservice.doSomething()`? Constructor, postconstruct, method? – SJuan76 Oct 20 '16 at 10:31
  • @PostConstruct public void init() – juanmorschrott Oct 20 '16 at 10:39
  • 1
    And have you defined the getters and setters for `pservice`? http://stackoverflow.com/questions/5165567/how-to-inject-entire-managed-bean-via-managedproperty-annotation – SJuan76 Oct 20 '16 at 10:52
  • Yes, the setter and getter are defined. I think the problem is the dependency instantiation. When I try to access to pservice methods, it returns null pointer exception because the dependency manager has not created an instance of pservice. – juanmorschrott Oct 20 '16 at 11:26

0 Answers0