1

我正在尝试在 Tomcat 8 上测试 JSF 2.3 的新功能,但没有任何效果。
与 JSF 2.2 兼容的代码可以在此配置中正常工作,但对于新的 JSF 2.3 功能,它会失败。
例如,以下代码导致应用程序启动失败。

WELD-001408: Unsatisfied dependencies for type FacesContext with qualifiers @Default

我的配置文件如下。

POM.xml 文件https://pastebin.com/84MEw2aS

<dependencies>
    <!-- CDI ..........................................-->
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
    </dependency>

    <!--JBoss/Weld Refrence Implementation for CDI on a Servlet Container -->    
    <dependency>
        <groupId>org.jboss.weld.servlet</groupId>
        <artifactId>weld-servlet</artifactId>
        <version>2.4.3.Final</version>
    </dependency>

    <!-- JSF ..........................................-->
    <dependency>
        <groupId>javax.faces</groupId>
        <artifactId>javax.faces-api</artifactId>
        <version>2.3</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.omnifaces</groupId>
        <artifactId>omnifaces</artifactId>
        <version>2.6.2</version>
    </dependency>  

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

上下文.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/JSF23"> 
    <Resource auth="Container"
              factory="org.jboss.weld.resources.ManagerObjectFactory"
              name="BeanManager"
              type="javax.enterprise.inject.spi.BeanManager"/>
</Context>


豆类.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
       version="1.2"
       bean-discovery-mode="all">
</beans>

web.xml

    <?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">
    <display-name>JSF 2.3</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>    
    <listener>
        <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
    </listener>
    <resource-env-ref>        
        <resource-env-ref-name>BeanManager</resource-env-ref-name>
        <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
    </resource-env-ref>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
</web-app>


版本

  • Apache Tomcat 8.0.27 或 Apache Tomcat 8.5.14
  • JDK 8。
  • NetBeans8.2
  • JSF 2.3
  • 焊接 2.4.3
  • Omnifaces 2.6.2

Tomcat日志如下

登录Tomcat https://pastebin.com/fufUfQtj

以下代码导致错误

package es.prueba.jsf23;

import javax.enterprise.context.ApplicationScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;

@ApplicationScoped
public class ApplicationBean {

    @Inject
    private FacesContext facesContext;

    public FacesContext getFacesContext() {
        return facesContext;
    }

    public void setFacesContext(FacesContext facesContext) {
        this.facesContext = facesContext;
    }    
}

我究竟做错了什么?

4

2 回答 2

0

您需要激活 JSF 2.3,默认情况下它与 JSF 2.2 兼容运行。

添加这样的类:

@FacesConfig(version = Version.JSF_2_3)
@ApplicationScoped
public class JSF23Activator {
}

另一个提示:

  • 检查 WEB-INF 文件夹中是否有“faces-config.xml”文件(使用 2.3 架构)
  • 检查您在 WEB-INF 文件夹中有一个 'beans.xml' 文件(带有 'bean-discovery-mode="all"' 属性)

您将通过此链接了解有关 Activator 的更多详细信息。

于 2019-08-08T22:06:15.493 回答
-6

使用新的 Glashfish 应用服务器。它被称为 Payara 服务器。这很棒。

于 2017-05-16T02:57:22.957 回答