java.lang.IllegalStateException:此环境中不提供CDI API。在org.omnifaces.config.BeanManager

时间:2015-07-23 11:42:09

标签: java eclipse jsf tomcat omnifaces

我试图使用omnifaces在byte[]中部署omnifaces 2.1,从托管bean方法显示图像,该方法返回<o:graphicImage> WEB_INF/lib public byte[] getImage() throws IOException{ return Utils.toByteArray(Faces.getResourceAsStream("/resources/images/loader.gif")); } 这是我的代码

Register.java

 <!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>

Home.xhtml

<o:graphicImage> Tag Library supports namespace: http://omnifaces.org/ui, but no tag was defined for name: graphicImage]

当我在eclipse中将omnifaces.jar添加到我的构建路径时,tomcat开始显示此错误omnifaces.jar。在WEB-INF/lib 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) 之后 它不会让tomcat启动并显示以下错误

ALTER PROCEDURE [dbo].[usp_currentDate]
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

    -- Insert statements for procedure here
    SELECT CONVERT(VARCHAR(10), GETDATE(), 101) 
END

我正在使用 JSF 2.0(Apache Myfaces),我还有用于上传文件的 tomahawk 1.1.14

1 个答案:

答案 0 :(得分:3)

OmniFaces 2.x需要CDI。另请参阅DownloadOmniFaces homepage部分:

  

OmniFaces 2.x

     

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

Tomcat作为一个准系统JSP / Servlet容器没有随附CDI。它仅适用于WildFlyTomEE等完整的Java EE容器。这同样适用于JSF(和JSTL),顺便说一下,你必须在Tomcat中手动安装它。

你有两个选择:

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

  2. 在Tomcat中手动安装CDI。

  3. 另见: