0

I have two web jsf projects which potentially could share some classes and beans, to reduce code duplicates.

One is a potential JNDI-ServiceLocator application scoped Bean. (Both web projects access RemoteBeans from same Host)

JNDI - ServiceLocator Bean:

@ManagedBean(name = "jndiServiceLocatorBean")
@ApplicationScoped
public class JndiServiceLocatorBean implements Serializable
{
    // code to cache jndi references
}

Abstract class with Bean as ManagedProperty:

public abstract class AJndiServiceLocator
{
    @ManagedProperty(value = "#{jndiServiceLocatorBean}")
    protected JndiServiceLocatorBean jndiServiceLocatorBean = null;

    public void setJndiServiceLocatorBean(final JndiServiceLocatorBean jndiServiceLocatorBean)
    {
        this.jndiServiceLocatorBean = jndiServiceLocatorBean;
    }
}

Example Bean from one of the projects:

@ManagedBean(name = "testBean")
@ApplicationScoped
public class TestBean extends AJndiServiceLocator implements Serializable
{
    // bean code - can now retrieve remote bean interfaces 
    // from super class
}

This code works as expected if the first classes JndiServiceLocatorBean and AJndiServiceLocator are in the source folder of the project.

But it does not works if I outsource those two classes into a subproject that is shared between both web projects. (Included on build path and marked as deployment entry.)

Injection Exception that occurs:

Schwerwiegend: Error Rendering View[/index.xhtml]
com.sun.faces.mgbean.ManagedBeanCreationException: Bei der Ressourcen-Einspeisung auf dem verwalteten Bean appBean ist ein Fehler aufgetreten.
    at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:229)
    at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:105)
    at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
    at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
    at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
    at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
djmj
  • 5,266
  • 4
  • 47
  • 89

1 Answers1

0

JSF won't scan every single JAR in the entire classpath for JSF artifacts, that would have been a very expensive job in a large webapp with tens of JARs. JSF will only scan JARs in /WEB-INF/lib folder containing a JSF 2.0 compatible /META-INF/faces-config.xml file.

Ensure that your JAR conforms this.

  • It must be in /WEB-INF/lib.
  • It must have a /META-INF/faces-config.xml with a JSF 2.0 compatible root declaration.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452