java - 如何在 JBoss AS 7.1.1 Final 中使用 JSF 2.1.14 Mojarra、Servlet 3.0 和 EL 2.2?

标签 java jsf-2 el jboss7.x servlet-3.0

在我的应用程序中,我想将 JSF 2.1.14 Mojarra 与 Servlet 3.0 和 EL 2.2 结合使用。服务器是JBoss-AS-7.1.1-Final。

现在我已经在 pom.xml 中添加了这些依赖项:

<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>2.1.14</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>2.1.14</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.0.1</version>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
<dependency>
    <groupId>javax.el</groupId>
    <artifactId>el-api</artifactId>
    <version>2.2</version>
</dependency>

这些 jar 位于/WEB-INF/lib 中。将应用程序部署到控制台的容器中后,我可以看到一条日志:

18:15:02,278 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-12) Initializing Mojarra 2.1.7-jbossorg-1 (20120227-1401) for context '/ActivityDatabase'

这显然意味着 JBoss 没有使用我放在 war 文件中的 JSF 版本。

在谷歌搜索并搜索其他SO线程后,我发现here ,我需要告诉容器使用 WAR 文件中提供的 JSF 包。所以我添加了:

<context-param>
    <param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
    <param-value>true</param-value>
</context-param>

在我的 web.xml 中。之后,当我部署 war 时,在部署时我收到异常:

18:39:57,665 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Critical error during deployment: : com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:376) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:223) [jsf-impl-2.1.14.jar:2.1.14]
        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09]
        at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]
Caused by: javax.faces.FacesException: Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider
        at com.sun.faces.spi.AnnotationProviderFactory.createAnnotationProvider(AnnotationProviderFactory.java:78) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigManager$AnnotationScanTask.<init>(ConfigManager.java:808) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:349) [jsf-impl-2.1.14.jar:2.1.14]
        ... 9 more

18:39:57,696 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/ActivityDatabase]] (MSC service thread 1-8) Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener: java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvi
der is not an instance of com.sun.faces.spi.AnnotationProvider
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:290) [jsf-impl-2.1.14.jar:2.1.14]
        at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09]
        at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]
Caused by: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:376) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:223) [jsf-impl-2.1.14.jar:2.1.14]
        ... 8 more
Caused by: javax.faces.FacesException: Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider
        at com.sun.faces.spi.AnnotationProviderFactory.createAnnotationProvider(AnnotationProviderFactory.java:78) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigManager$AnnotationScanTask.<init>(ConfigManager.java:808) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:349) [jsf-impl-2.1.14.jar:2.1.14]
        ... 9 more

18:39:57,743 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-8) Error listenerStart
18:39:57,758 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-8) Context [/ActivityDatabase] startup failed due to previous errors
18:39:57,758 SEVERE [javax.faces] (MSC service thread 1-8) Application was not properly initialized at startup, could not find Factory: javax.faces.application.ApplicationFactory. Attempting to find backup.
18:39:57,758 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Unexpected exception when attempting to tear down the Mojarra runtime: java.lang.IllegalStateException: Could not find backup for factory javax.faces.application.ApplicationFactory.
        at javax.faces.FactoryFinder$FactoryManager.getFactory(FactoryFinder.java:1010) [jsf-api-2.1.14.jar:2.1]
        at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:342) [jsf-api-2.1.14.jar:2.1]
        at com.sun.faces.config.InitFacesContext.getApplication(InitFacesContext.java:136) [jsf-impl-2.1.14.jar:2.1.14]
        at com.sun.faces.config.ConfigureListener.contextDestroyed(ConfigureListener.java:328) [jsf-impl-2.1.14.jar:2.1.14]
        at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:3489) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.stop(StandardContext.java:3999) [jbossweb-7.0.13.Final.jar:]
        at org.apache.catalina.core.StandardContext.start(StandardContext.java:3917) [jbossweb-7.0.13.Final.jar:]
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09]
        at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]

18:39:57,805 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC00001: Failed to start service jboss.web.deployment.default-host./ActivityDatabase: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./ActivityDatabase: JBAS018040: Failed to start context
        at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:95)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_09]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_09]
        at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_09]

18:39:57,821 INFO  [org.jboss.as] (MSC service thread 1-8) JBAS015951: Admin console listening on http://127.0.0.1:9990
18:39:57,836 ERROR [org.jboss.as] (MSC service thread 1-8) JBAS015875: JBoss AS 7.1.1.Final "Brontes" started (with errors) in 4446ms - Started 444 of 523 services (2 services failed or missing dependencies, 76 services are passive or on-demand)
18:39:58,039 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "ActivityDatabase.war" was rolled back with failure message {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./ActivityDatabase" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./ActivityDatabase: JBAS018040: Failed to start context"}}
18:39:58,179 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-16) JBAS015877: Stopped deployment ActivityDatabase.war in 145ms
18:39:58,179 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
JBAS014777:   Services which failed to start:      service jboss.web.deployment.default-host./ActivityDatabase: org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./ActivityDatabase: JBAS018040: Failed to start context

18:39:58,179 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014671: Failed services" => {"jboss.web.deployment.default-host./ActivityDatabase" => "org.jboss.msc.service.StartException in service jboss.web.deployment.default-host./ActivityDatabase: JBAS01
8040: Failed to start context"}}}}

我还尝试从 jboss-deployment-struct.xml 中排除 jsf 模块,如下所示:

<jboss-deployment-structure>
    <deployment>
        <exclusions>
            <module name="javax.faces.api" />
            <module name="com.sun.jsf-impl" />
            <module name="javax.faces.api" />
            <module name="com.sun.jsf-impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure> 

但运气不好,同样的错误。我仍在网上寻找解决方案,但没有任何效果。我也不确定 JBoss 是否使用 Servlet 3.0 和 EL 2.2。虽然我已经在 web.xml 中指定了 version="3.0"

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

    ---

</web-app>

任何建议都会对我很有帮助。

最佳答案

Caused by: javax.faces.FacesException: Class org.jboss.as.web.deployment.jsf.JandexAnnotationProvider is not an instance of com.sun.faces.spi.AnnotationProvider

这是在 JBoss 7.1.0 中首次发现的错误,并在 JBoss 7.1.3 中修复,另请参阅 JBoss AS 7 issue 3940 .

因此,至少升级到 7.1.3 应该可以解决这个问题。

关于java - 如何在 JBoss AS 7.1.1 Final 中使用 JSF 2.1.14 Mojarra、Servlet 3.0 和 EL 2.2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13879481/

相关文章:

java - 尝试在 Eclipse 中使用 selenium jar 文件启动 Firefox 浏览器

java - JPA @ElementCollection 注释是否始终产生一对多关系?

java - 等待资源释放

JSF:h:输出文本;当值为空字符串时如何显示破折号?

jsf - 在JSF2.0中,如何在facelets中写出cookies?

java - 如何处理使用套接字连接到服务器的多个客户端?

java - Primefaces 自动完成多个 - 在输入时选择输入值

jsf - 如果文件在整页刷新 (FPR) 后未呈现,我如何有条件地在 h :head, 中呈现 .js 文件?

jsf - 如何获取 PrimeFaces 轮播的当前索引?

javascript - JSP 循环的每次迭代后脚本运行两次