【问题标题】:Target Unreachable, identifier 'bean' resolved to null目标无法到达,标识符 \'bean\' 解析为空
【发布时间】:2022-12-12 16:16:44
【问题描述】:

在将“bean-discovery-mode”从“all”更改为“annotated”之前,CDI 运行良好。这是重现 PropertyNotFoundException 的示例,请帮助告知我错过了什么?

javax.el.PropertyNotFoundException: //C:/Users/abc/JavaWebTest/src/main/webapp/cdi.xhtml @22,39 value="#{requestTestBean.input}": 目标无法到达,标识符 'requestTestBean' 解析为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>

爪哇

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

【问题讨论】:

    标签: java weblogic cdi


    【解决方案1】:

    尝试删除 @javax.inject annotation.Named 注释?

    同时使用这两个注解,你想达到什么目的?

    @javax.inject.Named @javax.enterprise.context.RequestScoped

    据我所知,Named 需要使用它的“名称”将一个 bean 嵌入到其他 bean 中。为了与xhtml页面建立链接,RequestScoped就足够了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-20
      • 2012-02-22
      • 2014-06-12
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 2016-03-09
      相关资源
      最近更新 更多