2

每当我使用 @inject 时,我都会尝试在 tomcat 8 上设置 jsf 2.3 我一直遇到错误我已经在 stackoverflow.com 上搜索和搜索,但我找不到解决方案。我已经按照此处的@BalusC 示例在其上安装了 CDI (Weld)如何在 Tomcat 上安装和使用 CDI?但是我一直有不满意的依赖:没有 bean 与注入点匹配。我想不通我有什么遗漏吗?

配置Bean.java

import static javax.faces.annotation.FacesConfig.Version.JSF_2_3;
import javax.faces.annotation.FacesConfig;
@FacesConfig(
     // Activates CDI build-in beans
     version = JSF_2_3
)
public class ConfigurationBean {
}

豆类.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.1" bean-discovery-mode="all">
</beans>

面孔-config.xml

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
  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/web-facesconfig_2_3.xsd">
</faces-config>

PushBean.java

@Named
@ViewScoped
public class PushBean implements Serializable {
  @Inject @Push(channel="counter") //This is where i get the error message unsatisfied dependency: no bean matches the injection point
  private PushContext push;
}

对我来说,这段代码看起来不错,但我想知道它是否是 netbeans 错误。我试过不使用spring,只使用带有jsf的tomcat,我仍然收到相同的错误消息。我在堆栈跟踪中找不到任何错误消息。 netbeans 中警告消息的屏幕截图

4

2 回答 2

2

Spring 不是一个完整的 CDI 容器,仅“知道”@Named@Inject注释,因此不(很可能)将@Push注释识别为限定符并且找不到 bean 并抛出您得到的错误(发布显式错误和堆栈跟踪是顺便说一句你应该总是在一个问题中做的事情!)

也可以看看:

于 2018-04-30T09:46:32.433 回答
-1

我建议检查你的范围。内置的 CDI 范围是 @ApplicationScoped、@SessionScoped、@ConversationScoped 和 @RequestScoped。CDI 中没有 @ViewScoped 注释。您可以注入相同级别或更广泛的范围,但不能注入更小的范围(例如,您不能将@RequestScoped 注入@SessionScoped bean)

于 2018-05-29T12:46:55.390 回答