【发布时间】:2017-10-11 03:36:56
【问题描述】:
我正在尝试在 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>
context.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>
bean.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;
}
}
我做错了什么?
【问题讨论】:
-
javax 中的依赖验证 api jar 似乎丢失了,正如堆栈跟踪中所指出的那样。您必须将其添加为依赖项。
-
我相信在这种情况下validation-api jar不是必需的。无论如何,我已经尝试添加这个 api,它给了我同样的错误。
-
jsf2.3中似乎引入了CDI的新特性,与之前的版本不同。 facescontext 注入在 jsf 2.3 中似乎没有任何限定符,例如`@Default 或 @Any`。您可能必须删除限定符。请参阅arjan-tijms.omnifaces.org/p/jsf-23.html#1417
-
我不明白我必须删除哪些限定词。我的代码与 Arjan Tijms 在以下链接 arjan-tijms.omnifaces.org/p/jsf-23.html#1412 中显示的代码相同
-
从堆栈跟踪中可以看出,您有“@Inject @Any”私有 beans.PhonePrefixServiceBean.facesContext”。如果是这样,那么“@Any”是一个限定符。
标签: jsf jakarta-ee tomcat8 jboss-weld jsf-2.3