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

问题描述 投票:0回答:1

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

下面是我的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 bean,但如你所见,我有beans.xml。

jsf jakarta-ee dependency-injection glassfish cdi
1个回答
0
投票

这不是OP的问题(考虑到发布的文件树),但可能对其他由于不同问题而出现相同错误信息的人有帮助。

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

请看 参考文献1参考文献2 也出现在 此处.

© www.soinside.com 2019 - 2024. All rights reserved.