CDI一直工作良好,直到“bean-discovery-mode”从“all”更改为“annotated”。下面是复制PropertyNotFoundException的示例,请帮助建议我错过了什么?
javax.el.PropertyNotFoundException: //C:/Users/abc/JavaWebTest/src/main/webapp/cdi.xhtml @22,39 value="#{requestTestBean.input}": Target Unreachable, identifier 'requestTestBean' resolved to null at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
联系我们
<!DOCTYPE HTML>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions">
<h:head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0" />
<title>CDI Test</title>
</h:head>
<h:body>
<ui:debug hotkey="x" />
<h:form id="form">
Name: <h:inputText
id="input"
value="#{requestTestBean.input}" />
<h:commandButton
value="Submit"
action="#{requestTestBean.submit()}" />
</h:form>
#{requestTestBean.output}
</h:body>
</html>
java
package dev;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@javax.inject.Named
@javax.enterprise.context.RequestScoped
public class RequestTestBean implements java.io.Serializable {
static final long serialVersionUID = 1L;
static final Logger logger = LogManager.getLogger();
String input;
String output;
public RequestTestBean() {
logger.debug(this);
}
@javax.annotation.PostConstruct
public void PostConstruct() {
logger.debug(this);
}
@javax.annotation.PreDestroy
public void PreDestroy() {
logger.debug(this);
}
public String submit() {
logger.debug("input: {}", this.input);
this.output = "Hello " + this.input;
return null;
}
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
public String getOutput() {
return output;
}
public void setOutput(String output) {
this.output = output;
}
}
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="annotated">
<scan>
<!-- Prevent CDI deployment failure due to java.lang.NoClassDefFoundError -->
<exclude name="org.apache.**" />
</scan>
</beans>
Weblogic 12.2 Java 8 Servlet 3.1 JSF 2.2 CDI 1.1 EJB 3.2
1条答案
按热度按时间hpxqektj1#
尝试删除
@javax.inject annotation.Named
注解?您希望同时使用这两个注解来实现什么目的?
@javax.inject.Named
@javax.enterprise.context.RequestScoped
据我所知,
Named
需要使用它的“名称”将bean嵌入到其他bean中。为了与xhtml
页面建立链接,RequestScoped
就足够了。