Question

I have an application scoped bean to hold the information in my database. After its instantiation it should fetch the data, so I annotated the method with @PostConstruct. As soon as I request the jsf page where this bean is referenced the server log explodes! I think it somehow recurses and the only stacktrace I get is that a System Exception occurred during the repBean.acceptVisitor(Visitor); method. The server log then gets several GB big and I have to manually delete it in order to have free disk space. If I delete the @PostConstruct annotation there are no exceptions. After calling the update() method from another bean the repositoryContent variable is updated properly and contains the information. The only problem then is that my jsf page doesn't display the content for some strange reason.

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

    private ArrayList<ViewFolder> repositoryContent;

    @EJB
    RepositoryService repBean;

    @PostConstruct
    public void update() {
       RepositoryVisitor Visitor = new RepositoryVisitor();
       repBean.acceptVisitor(Visitor);
       repositoryContent = Visitor.getList();
   }
}
Was it helpful?

Solution

This is not normal behaviour.

One of the following lines

   RepositoryVisitor Visitor = new RepositoryVisitor();
   repBean.acceptVisitor(Visitor);
   repositoryContent = Visitor.getList();

is indirectly evaluating the EL expression #{indexBean} which in turn causes the bean being constructed once again, because it is not been put in service yet. It would only be put in service (and thus available as a concrete #{indexBean}) when the @PostConstruct finishes. This all causes an infinite loop.

You might need to do some refactoring, or to pass the application scoped bean instance itself to the method call so that it can be used directly instead of being referenced by an EL expression.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top