0

I have an ear package that uses some libraries to re-use some common things. One of these common things is a SettingsBean that does some generic settings for the application. However, the SettingsBean cannot be found with CDI, even though there is a beans.xml file present.

Here is the file structure of my EAR file:

META-INF
lib
main-ejb.jar
main-web.war
|
`-- WEB-INF
|   |
|   `-- lib
|   |   |
|   |   `-- primefaces.jar
|   |       common-web.jar
|   |       |
|   |       `-- META-INF
|   |       |   |
|   |       |   `-- resources
|   |       |   |   |
|   |       |   |   `-- WEB-INF
|   |       |   |       |
|   |       |   |       `-- mainTemplate.xhtml
|   |       |   `-- maven
|   |       |   `-- MANIFEST.MF
|   |       |   `-- beans.xml
|   |       `-- com
|   |           |
|   |           `-- SettingsBean.class
|   `-- classes
|   `-- web.xml
|   `-- glassfish-web.xml
|   `-- faces-config.xml
|   `-- beans.xml
`-- META-INF
`-- index.xhtml

SettingsBean:

@Named(value = "settingsBean")
@SessionScoped
public class SettingsBean implements Serializable {
    //Code here
}

index.xhtml:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/mainTemplate.xhtml">
    <ui:define name="content">
        Content comes here
    </ui:define>
</ui:composition>

In the mainTemplates.xhtml I call the settingsBean. So when I call the index.xhtml page, I get following error:

Target Unreachable, identifier 'settingsBean' resolved to null 

javax.el.PropertyNotFoundException: Target Unreachable, identifier 'settingsBean' resolved to null
at com.sun.el.parser.AstValue.getTarget(AstValue.java:174)
at com.sun.el.parser.AstValue.getType(AstValue.java:86)
at com.sun.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:201)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:132)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:171)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1045)
at javax.faces.component.UIInput.validate(UIInput.java:975)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1248)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at org.primefaces.component.layout.Layout.processValidators(Layout.java:233)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:722)

Any help on how I can access the Named bean that is inside the library jar? What I've read so far is that you need to have the beans.xml file inside it, otherwise CDI will not scan the jar for Named beans, but as you can see, I have the beans.xml.

Erates
  • 596
  • 1
  • 6
  • 22
  • GF version? What's content of `/WEB-INF/beans.xml`? – BalusC May 29 '15 at 09:54
  • Application is running on Glassfish 4.1, and beans.xml is just empty. – Erates May 29 '15 at 09:55
  • OK, Java EE 7 thus. Hmm, should work. What if you use CDI 1.1 beans.xml content as shown in this answer? http://stackoverflow.com/questions/30128395/identifying-and-solving-javax-el-propertynotfoundexception-target-unreachable – BalusC May 29 '15 at 09:56
  • From which package are you importing `@SessionScoped`? – unwichtich May 29 '15 at 15:25

1 Answers1

0

This is not OP's problem (given the posted tree of the files), but could be helpful for other people with the same error message due to a different problem.

The kind of error happens when the bean cannot be identified during bean discovery. One possible reason it isn't discovered is if the JAR isn't marked for having beans, in which case it will not be scanned. The solution was to make sure there was a copy of beans.xml in both the WAR file under WEB-INF and in the JAR file under META-INF.

See reference 1 and reference 2 which also appear under here.

Pixelstix
  • 612
  • 5
  • 18