java.lang.IllegalStateException: CDI API在此环境中不可用.在org.omnifa



我试图显示一个图像从一个托管bean方法返回byte[]<o:graphicImage>使用omnifaces I部署的omnifaces 2.1在WEB_INF/lib这是我的代码

Register.java

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

        }

Home.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>

当我在eclipse中添加omnifaces.jar到我的构建路径时,tomcat启动时显示了这个错误<o:graphicImage> Tag Library supports namespace: http://omnifaces.org/ui, but no tag was defined for name: graphicImage]。在WEB-INF/lib中的omnifaces.jar之后它不允许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用于上传文件。

x需要CDI。参见OmniFaces主页的下载部分:

OmniFaces 2. x

Required: Java 1.7, JSF 2.2, EL 2.2, Servlet 3.0和CDI 1.1
可选: BV 1.0

Tomcat作为一个裸机JSP/Servlet容器并没有随CDI一起发货。它只在成熟的Java EE容器(如WildFly和TomEE)中可用。这同样适用于JSF(和JSTL),顺便说一下,您必须在Tomcat中手动安装它。

你有两个选择:

  1. 将Tomcat替换为TomEE或其他Java EE容器

  2. 在Tomcat中手动安装CDI

参见:

    如何在Tomcat上安装和使用CDI ?-包含详细的安装说明

相关内容

  • 没有找到相关文章

最新更新