Maven JSF-2.3找不到我的@Named CDI-1.2托管bean

Maven JSF-2.3找不到我的@Named CDI-1.2托管bean,maven,jakarta-ee,websphere,cdi,jsf-2.3,Maven,Jakarta Ee,Websphere,Cdi,Jsf 2.3,在最近从2.2升级到JSF2.3之后,我注意到@ManagedBean已被弃用,在一些研究发现我应该使用CDI-1.2托管bean和@Named注释之后 但是,在切换到@Named之后,JSF页面找不到托管bean: javax.servlet.ServletException:/index.xhtml@38,38 value=“#{controller.telstraPass}”:无法访问目标,标识符“controller”解析为null 我正在使用Maven、eclipse和WebSpher

在最近从2.2升级到JSF2.3之后,我注意到@ManagedBean已被弃用,在一些研究发现我应该使用CDI-1.2托管bean和@Named注释之后

但是,在切换到@Named之后,JSF页面找不到托管bean:

javax.servlet.ServletException:/index.xhtml@38,38 value=“#{controller.telstraPass}”:无法访问目标,标识符“controller”解析为null

我正在使用Maven、eclipse和WebSphereApplicationServerLiberty v16.0.0.4 不知道我做错了什么,以下是相关文件:

Controller.java:

package ManagedBeans;

import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;

import javax.enterprise.context.SessionScoped;
import javax.inject.Named;
import javax.servlet.http.Part;

import Main.FileHandler;
import Main.IBMEmployee;

@Named("controller")
@SessionScoped
public class Controller implements Serializable {

    private Part telstraCustomersFile;
    private Part terminateesFile;
    private String telstraPass;
    private String termineesPass;
    private String exception;
    private String exceptionTrace;
    private FileHandler fileHandler = new FileHandler();
    private IBMEmployee[] potentialMatches;

    public String perform()
    {
        try {
            fileHandler.process(telstraCustomersFile, terminateesFile, telstraPass, termineesPass);
            potentialMatches = fileHandler.potentialMatches;
        }
        catch (Exception ex) {
            StringWriter errors = new StringWriter();
            ex.printStackTrace(new PrintWriter(errors));
            exception = ex.toString();
            exceptionTrace = errors.toString();

            return ("errorPage.xhtml");
        }

        return ("searchExcel.xhtml");
    }

    public void setTelstraPass(String value) { telstraPass = value; }
    public String getTelstraPass() { return telstraPass; }
    public void setTermineesPass(String value) { termineesPass = value; }
    public String getTermineesPass() { return termineesPass; }
    public void setTelstraCustomersFile(Part file) { telstraCustomersFile = file; }
    public Part getTelstraCustomersFile() { return telstraCustomersFile; }
    public void setTerminateesFile(Part file) { terminateesFile = file; }
    public Part getTerminateesFile() { return terminateesFile; }
    public String getException() { return exception; }
    public String getExceptionTrace() { return exceptionTrace; }
    public IBMEmployee[] getExactMatches() { return fileHandler.exactMatches; }
    public IBMEmployee[] getPotentialMatches() { return potentialMatches; }
}
index.xhtml:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">   
      <h:head>
        <title>Termination Checklist</title>
        <h:outputScript name="js/scripts.js"/>      
        <h:outputStylesheet name="css/PageFormat.css"/>

        Created By Jerry Boyaji
        <h:graphicImage id="IBMLogo" name="images/IBM-logo.jpg"  width="101" height="48"/>
    </h:head>
    <h:body onload="enableDisableSubmitBtn()">
        <div id="ContentFrame">
            <h1>Corporate Account Termination Application (CATA)</h1>
            <h3>Excel Search: <br/> Select your spreadsheet files to upload:</h3>
            <br/>
            <br/>
            <h:form id="excelInputForm" enctype="multipart/form-data" 
                name="UploadForm" 
                method="Post">

                Telstra Spreadsheet File: 

                <br/>
                <h:inputFile
                    id="telstraCustomers" 
                    name="telstra file" 
                    size="40" 
                    value="#{controller.telstraCustomersFile}"
                    required="True"
                    onchange="enableDisableSubmitBtn()"/>

                Password if Applicable: 
                <h:inputSecret
                    id="telstraSpreadsheetPassword"
                    value="#{controller.telstraPass}"
                    label="Password if Applicable"/>

                <br/>
                <br/>

                Termination Spreadsheet File: 
                <br/>           
                <h:inputFile
                    id="terminatees" 
                    name="termination file" 
                    size="40"
                    value="#{controller.terminateesFile}"
                    required="True"
                    onchange="enableDisableSubmitBtn()" />

                Password if Applicable: 
                <h:inputSecret
                    id="termineesSpreadsheetPassword"
                    value="#{controller.termineesPass}"
                    label="Password if Applicable"/>    

                <br/>
                <br/>

                <h:commandButton 
                    id="submit"
                    value="Upload and Continue" 
                    type = "submit"
                    action="#{controller.perform}"/>

            </h:form>
        </div>
    </h:body>
</html>

终止检查表
由Jerry Boyaji创作
公司账户终止申请(CATA)
Excel搜索:
选择要上载的电子表格文件:

澳大利亚电信电子表格文件:
密码(如适用):

终止电子表格文件:
密码(如适用):

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>MainApplication</display-name>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
    <context-param>
        <description>
        State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <display-name>HTTPS Redirect Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>MainApplication</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>
</web-app>

主要应用
index.xhtml
状态保存方法:“客户端”或“服务器”(=默认值)。参见JSF规范2.5.2
javax.faces.STATE_保存方法
客户
javax.servlet.jsp.jstl.fmt.localizationContext
资源.应用
Facesservlet
javax.faces.webapp.FacesServlet
1.
Facesservlet
*.xhtml
HTTPS重定向安全约束
主要应用
/*
保密的
Server.xml:

<server description="jerry's local server">

    <!-- Enable features -->
    <featureManager>
        <feature>localConnector-1.0</feature>
        <feature>websocket-1.1</feature>
        <feature>appSecurity-2.0</feature>
        <feature>cdi-1.2<feature>
        <feature>jsp-2.3</feature>
    </featureManager>

    <basicRegistry id="basic">
      <user name="admin" password="****"/>
   </basicRegistry>

   <administrator-role>
      <user>admin</user>
   </administrator-role>

    <remoteFileAccess>
        <writeDir>${server.config.dir}</writeDir>
    </remoteFileAccess>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint host="localhost" httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

    <applicationMonitor updateTrigger="mbean"/>
    <keyStore id="defaultKeyStore" password="****"/>

    <webApplication id="MainApplication" location="MainApplication.war" name="MainApplication"/>
</server>

localConnector-1.0
websocket-1.1
appSecurity-2.0
cdi-1.2
jsp-2.3
管理
${server.config.dir}
pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Termination-Checklist-Maven</groupId>
  <artifactId>MainApplication</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>MainApplication</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <pluginRepositories>
        <!-- Configure WASdev repository -->
        <pluginRepository>
            <id>WASdev</id>
            <name>WASdev Repository</name>
            <url>http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/</url>
            <layout>default</layout>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </pluginRepository>
    </pluginRepositories>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.0.0</version>
        <configuration>
          <webXml>WebContent/WEB-INF/web.xml</webXml>
        </configuration>
      </plugin>
      <plugin>
            <groupId>com.ibm.websphere.wlp.maven.plugins</groupId>
            <artifactId>liberty-maven-plugin</artifactId> 
            <version>1.0</version>
            <configuration>
                <serverHome>/Applications/WebProfile</serverHome>
            </configuration>
      </plugin>
    </plugins>
  </build>

  <repositories>
    <!--other repositories if any-->
    <repository>
        <id>project.local</id>
        <name>project</name>
        <url>file:${project.basedir}/repo</url>
    </repository>
  </repositories>


  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.faces</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>javax.enterprise</groupId>
        <artifactId>cdi-api</artifactId>
        <version>1.2</version>
        <scope>provided<scope>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>3.16-beta2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.16-beta2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.0.4</version>
    </dependency>
    <dependency>
        <groupId>javax.json</groupId>
        <artifactId>javax.json-api</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>3.16-beta2</version>
    </dependency>
        <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
    </dependency>
  </dependencies>
</project>

4.0.0
终止检查表Maven
主要应用
0.0.1-快照
战争
主要应用
http://maven.apache.org
UTF-8
瓦斯德夫
WASdev存储库
http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/
违约
假的
真的
maven战争插件
3.0.0
WebContent/WEB-INF/WEB.xml
com.ibm.websphere.wlp.maven.plugins
liberty maven插件
1
/应用程序/网站简介
项目.本地
项目
文件:${project.basedir}/repo
朱尼特
朱尼特
3.8.1
测试
玻璃鱼
javax.faces
2.3.0
javax.enterprise
CDIAPI
1.2
假如
org.apache.poi
poi
3.16-β2
org.apache.poi
poi ooxml
3.16-β2
玻璃鱼
javax.json
1.0.4
javax.json
javax.json-api
1
org.apache.poi
poi ooxml模式
3.16-β2
javax.servlet
javax.servlet-api
3.1.0
faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.3"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_3.xsd"> 
</faces-config>

我的WEB-INF文件夹中还有一个空的beans.xml文件,其中包含WEB.xml和faces-config.xml


就我所见,我已经把一切都做好了,我没有JSF或CDI的竞争实现,也没有使用JSF包中的任何作用域。我完全不知道这为什么不起作用…

正如Gas指出的,问题是was中内置的CDI功能不能与外部JSF库一起工作

请参阅IBM支持页上的,确认了这一点


使用JSF-2.2仍然使用web套接字的一种方法是使用@Gas指出的Javax.websocket包。然而,这种web套接字实现的局限性在于,仅将SessionScoped ManagedBean中包含的数据发送到该会话的客户端远不如我所希望的那样简单,因为它将使用JSF-2.3中的f:websocket,由于我只看到
jsp-2.3
。我使用的是jsf-2.3,它与my.war打包在一起,正如您在my pom.xml中看到的那样,为什么要添加以前的版本来解决这个问题?Jsp-2.3也是必需的,因为没有它任何东西都不能工作(我认为,因为jsf-2.3或cdi-1.2需要它作为一个提供的依赖项,我不记得它是什么),您的应用程序非常简单,可以使用内置的jsf-2.2运行,这是Java EE 7的默认设置,因此仅为了测试,您应该尝试从war中删除任何外部jsf LIB,升级到jsf-2.3以利用异步性,并恢复到jsf-2.3(作为一个外部库)@ManagedBean注释,就像我以前使用的一样,仍然可以像使用jsf-2.2默认特性一样工作啊,是的,这就是问题所在。只有提供的jsf实现可以与CDI注释一起使用。检查这些页面-和。因此,您要么使用提供的CDI,要么使用定制的JSFbean。