gpt4 book ai didi

java.lang.IllegalStateException : CDI API is not available in this environment. 在 org.omnifaces.config.BeanManager

转载 作者:行者123 更新时间:2023-11-28 22:37:16 40 4
gpt4 key购买 nike

我正在尝试显示来自托管 bean 方法的图像,该方法返回 byte[]<o:graphicImage>使用 omnifaces 我在 WEB_INF/lib 中部署了 omnifaces 2.1这是我的代码

注册.java

public byte[] getImage() throws IOException{
return Utils.toByteArray(Faces.getResourceAsStream("/resources/images/loader.gif"));


}

首页.xhtml

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<h:outputStylesheet library="css" name="style.css"></h:outputStylesheet>
<style>
.center {
align: center;
}
</style>

</h:head>
<h:body>
<h:form>
<table style="float:right;margin-top:5px;">
<tr><td><h:commandLink action="/user/second.xhtml" style="float:right;">Second page</h:commandLink></td>
<td><h:commandLink action="#{login.logout}" style="float:right;">Logout</h:commandLink></td></tr>
</table>
</h:form>
<h:form>
<div style="margin: auto;">
<h:messages globalOnly="true" infoStyle="display:none" styleClass="error" style="list-style-type:none;"/>
<h:messages globalOnly="true" errorStyle="display:none" styleClass="green" style="list-style-type:none;"/>
<h4 align="center">Welcome to JSF #{login.username} Dude</h4>

<h3 align="center">User Profile</h3>
<h:dataTable value="#{register.getUser(login.username)}" var="info"
styleClass="center" style="margin:auto;" border="1">
<h:column>
<f:facet name="header">Image</f:facet>
<o:graphicImage value="#{register.getImage()}" type="jpg" dataURI="true"/>
</h:column>

<h:column>
<!-- column header -->
<f:facet name="header">Email</f:facet>
<!-- row record -->
<h:outputText value="#{info.email}"
rendered="#{not register.edit}" />
<!-- <h:inputText value="#{info.email}" rendered="#{not register.edit}" /> -->
</h:column>
<h:column>
<!-- column header -->
<f:facet name="header">First Name</f:facet>
<!-- row record -->

<h:outputText value="#{info.first}" rendered="#{not register.edit}" />
<!-- <h:inputText value="#{info.first}" rendered="#{not register.edit}" /> -->
</h:column>
<h:column>
<!-- column header -->
<f:facet name="header">Last name</f:facet>
<!-- row record -->

<h:outputText value="#{info.last}" rendered="#{not register.edit}" />
<!-- <h:inputText value="#{info.last}" rendered="#{not register.edit}" /> -->
</h:column>
<h:column>
<!-- column header -->
<f:facet name="header">Phone</f:facet>
<!-- row record -->

<h:outputText value="#{info.phone}"
rendered="#{not register.edit}" />
<!-- <h:inputText value="#{info.phone}" rendered="#{not register.edit}" /> -->
</h:column>
<h:column>
<h:commandButton value="Update" action="/user/Updateprofile.xhtml">

</h:commandButton>

</h:column>

</h:dataTable>
</div>
</h:form>


</h:body>
</html>

一开始tomcat启动显示这个错误<o:graphicImage> Tag Library supports namespace: http://omnifaces.org/ui, but no tag was defined for name: graphicImage]当我在 eclipse 中将 omnifaces.jar 添加到我的构建路径中时。 omnifaces.jar之后在WEB-INF/lib它不让 tomcat 启动并显示以下错误

   java.lang.ExceptionInInitializerError
at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:69)
at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89)
at org.omnifaces.application.OmniApplicationFactory.getApplication(OmniApplicationFactory.java:54)
at org.apache.myfaces.config.FacesConfigurator.configureApplication(FacesConfigurator.java:1926)
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:529)
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:296)
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:118)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: CDI API is not available in this environment.
at org.omnifaces.config.BeanManager.<init>(BeanManager.java:88)
at org.omnifaces.config.BeanManager.<clinit>(BeanManager.java:49)
... 18 more
Caused by: java.lang.ClassNotFoundException: javax.enterprise.inject.spi.BeanManager
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.omnifaces.config.BeanManager.<init>(BeanManager.java:82)
... 19 more

Jul 23, 2015 5:16:06 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.omnifaces.ApplicationListener
java.lang.NoClassDefFoundError: Could not initialize class org.omnifaces.config.BeanManager
at org.omnifaces.ApplicationListener.checkCDIAvailable(ApplicationListener.java:63)
at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:55)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Jul 23, 2015 5:16:06 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Jul 23, 2015 5:16:06 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/First] startup failed due to previous errors
Jul 23, 2015 5:16:06 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.apache.myfaces.webapp.StartupServletContextListener
java.lang.NoClassDefFoundError: Could not initialize class org.omnifaces.config.BeanManager
at org.omnifaces.application.OmniApplication.<init>(OmniApplication.java:69)
at org.omnifaces.application.OmniApplicationFactory.createOmniApplication(OmniApplicationFactory.java:89)
at org.omnifaces.application.OmniApplicationFactory.getApplication(OmniApplicationFactory.java:54)
at org.apache.myfaces.context.servlet.FacesContextImplBase.getApplication(FacesContextImplBase.java:131)
at org.apache.myfaces.webapp.AbstractFacesInitializer._dispatchApplicationEvent(AbstractFacesInitializer.java:239)
at org.apache.myfaces.webapp.AbstractFacesInitializer.destroyFaces(AbstractFacesInitializer.java:273)
at org.apache.myfaces.webapp.StartupServletContextListener.contextDestroyed(StartupServletContextListener.java:153)
at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:5063)
at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5723)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

我使用的是 JSF 2.0(Apache Myfaces),我还使用 tomahawk 1.1.14 来上传文件。

最佳答案

OmniFaces 2.x 需要 CDI .另见 DownloadOmniFaces homepage :

OmniFaces 2.x

Required: Java 1.7, JSF 2.2, EL 2.2, Servlet 3.0 and CDI 1.1
Optional: BV 1.0

作为准系统 JSP/Servlet 容器的 Tomcat 不随 CDI 一起提供。它仅在成熟的 Java EE 容器中可用,如 WildFlyTomEE .这同样适用于 JSF(和 JSTL),顺便说一下,您必须在 Tomcat 中手动安装它。

您有 2 个选择:

  1. 用 TomEE 或任何其他 Java EE 容器替换 Tomcat。

  2. 在 Tomcat 中手动安装 CDI。

另见:

关于java.lang.IllegalStateException : CDI API is not available in this environment. 在 org.omnifaces.config.BeanManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31586337/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com