在库jar中找不到名为bean的CDI



我有一个ear包,它使用一些库来重用一些常见的东西。其中一个常见的东西是为应用程序做一些通用设置的SettingsBean。但是,使用CDI无法找到SettingsBean,即使存在beans.xml文件。

下面是我的EAR文件的文件结构:
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>

mainTemplates.xhtml中,我调用settingsBean。因此,当调用index.xhtml页面时,会得到以下错误:

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)

关于如何访问库jar内的Named bean的任何帮助?到目前为止,我所读到的是,您需要在其中包含beans.xml文件,否则CDI将不会扫描jar以查找Named beans,但是正如您所看到的,我有beans.xml。

这不是OP的问题(给定已发布的文件树),但对于由于不同问题而出现相同错误消息的其他人可能会有所帮助。

这种错误发生在bean发现期间无法识别bean时。它没有被发现的一个可能原因是JAR没有被标记为具有bean,在这种情况下,它将不会被扫描。解决方案是确保在WEB-INF下的WAR文件和META-INF下的JAR文件中都有beans.xml的副本。

参见参考文献1和参考文献2

相关内容

  • 没有找到相关文章

最新更新