每当我使用 @inject 时,我都会尝试在 tomcat 8 上设置 jsf 2.3 我一直遇到错误,我已经在 stackoverflow.com 上进行了谷歌搜索和搜索,但我找不到解决方案。我已经按照这里的 @BalusC 示例安装了 CDI (Weld)如何在Tomcat上安装和使用CDI? https://stackoverflow.com/questions/18995951/how-to-install-and-use-cdi-on-tomcat但我仍然有不满意的依赖性:没有 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 {
}
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>
面孔配置.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;
}
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
and @Inject
注释,因此(很可能)无法识别@Push
注释作为限定符,无法找到 bean 并抛出您得到的错误(发布显式错误和堆栈跟踪是您在问题中应该始终执行的操作!)
也可以看看:
- 注入实例:Spring 和 CDI 兼容性 https://stackoverflow.com/questions/44458750/inject-instanceinterface-spring-and-cdi-compatibility
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)