【发布时间】:2014-07-31 17:42:24
【问题描述】:
我有以下 bean:
@javax.inject.Named
@javax.faces.view.ViewScoped
public class UserController implements Serializable{
在我的 jsf 页面中,我正在访问它:
<h:outputText value="#{userController.model.detail.name}"/>
当我调试它时,我注意到我的 @PostConstruct 方法没有在 userController 上调用,所以创建 bean 肯定有一些问题。我在WEB-INF/ 中有beans.xml 文件。我需要其他东西才能让 CDI 正常工作。我正在使用 Wildfly 8.1。我在日志中没有错误。
编辑:
我已经添加了我的 build.gradle
dependencies {
compile 'com.sun.faces:jsf-api:2.2.7'
testCompile group: 'junit', name: 'junit', version: '4.11'
providedCompile 'org.jboss.spec:jboss-javaee-all-7.0:1.0.1.Final'
compile group: 'org.primefaces', name: 'primefaces', version:'5.0'
providedCompile group: 'javax.servlet', name: 'servlet-api', version:'2.5'
providedCompile group: 'javax.servlet', name: 'jsp-api', version:'2.0'
}
【问题讨论】:
-
您使用的是哪个 CDI 版本?我不确定,但我记得从 CDI 1.1 开始,您不再需要 beans.xml。
-
我正在使用来自 org.jboss.spec:jboss-javaee-all-7.0:1.0.1.Final 的版本,这将是 1.0 版
-
通过在web.xml中添加缺少的jsf映射解决。
-
@John:你应该把它写成答案并接受它。
-
我可以在 2 天内接受我自己的答案。