JSF 2.3 CDI无法在tomcat上运行 [英] JSF 2.3 CDI not working on tomcat
问题描述
每当我使用@inject时,我都试图在tomcat 8上设置jsf 2.3.我已经在@BalusC示例下面从这里在其上安装了CDI(焊接)如何在Tomcat上安装和使用CDI?但是我一直没有满足要求:没有bean与注入点匹配.我不知道有什么我想念的吗?
I am trying to set up jsf 2.3 on tomcat 8 whenever I used @inject I keep having an error with it I have googled and searched on stackoverflow.com yet I can't find a solution to it. I have already installed CDI (Weld) on it following @BalusC example from here How to install and use CDI on Tomcat? yet I keep having unsatisfied dependency: no bean matches the injection point. I can't figure it out is there anything i am missing?
ConfigurationBean.java
ConfigurationBean.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 {
}
beans.xml
beans.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>
faces-config.xml
faces-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
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我仍然得到相同的错误消息.我在stacktrace中找不到任何错误消息.
For me this code looks fine but am wondering if it is netbeans bug. I tried that without using spring just only tomcat with jsf i still get the same error message. I couldn't find any error message inside the stacktrace.
推荐答案
Spring不是完全成熟的CDI容器,仅知道" @Named
和@Inject
批注,因此(很可能)无法识别@Push
作为限定符的注释,无法找到Bean并抛出您得到的错误(发布明确的错误,并且stacktrace是您在问题中始终应该做的事情!)
Spring is NOT a full blown CDI container and only 'knows' the @Named
and @Inject
annotations and consequently does not (most likely) recognize the @Push
annotation as a qualifier and cannot find the bean and throws the error you get (posting an explicit error and stacktrace is btw something you should always do in a question!)
另请参见:
这篇关于JSF 2.3 CDI无法在tomcat上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!