簡體   English   中英

CDI bean在glassfish 5內部版本25中導致javax.el.PropertyNotFoundException

[英]CDI bean results in javax.el.PropertyNotFoundException in glassfish 5 build 25

我使用Java 8,glassfish 5 build 25,Eclipse。 我正在嘗試從Java EE 7升級到Java EE8。因此,我從這個簡單的示例開始。

在web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
    id="WebApp_ID" version="4.0">
    <display-name>Play ID</display-name>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</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>
</web-app>

CDI Bean:

@Named
@ViewScoped
public class CommentFront implements Serializable {
    private static final long serialVersionUID = 1L;

    public void addComment() {
        System.out.println("I don’t work: ");   
    } 
}

簡單的JSF頁面comment.xhtml

<!DOCTYPE html >
<html lang="en" 
    xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
    >
<h:head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
    <title>Derbyware</title>

<h:body>
    <h:form id="form">
        <h:commandButton id="OneBtn" value="1 Comment" action="#{commentFront.addComment()}" >  
        </h:commandButton>

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

錯誤:

javax.el.PropertyNotFoundException: /comment.xhtml @17,89 action="#{commentFront.addComment()}": Target Unreachable, identifier 'commentFront' resolved to null

當我第一次啟動glassfish時,它會打印:

    2018-10-31T14:26:57.985+0000|Info: WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<T>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.

    2018-10-31T14:26:58.032+0000|WARN: WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.cdi.transaction.TransactionalInterceptorMandatory is deprecated from CDI 1.1!
    ...
    2018-10-31T14:26:58.048+0000|WARN: WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!
    2018-10-31T14:26:58.282+0000|Info: Initializing Soteria 1.0 for context '/Play_ID'
    2018-10-31T14:26:58.282+0000|Info: Initializing Mojarra 2.3.2 ( 20170627-2139 e63598abf2ed2bb1a24674f308a734e0dce18a72) for context '/Play_ID'
    2018-10-31T14:26:58.829+0000|Info: Loading application [Play_ID] at [/Play_ID]
    2018-10-31T14:26:58.938+0000|Info: Play_ID was successfully deployed in 1,932 milliseconds.

為什么像這樣簡單的東西在Glassfish 5上不起作用?

解決方案1:

我從將faces-config.xml從2.2更改為2.3的答案中使用了此方法, 導致javax.el.PropertyNotFoundException:目標無法訪問,標識符“ bean”解析為null

import javax.enterprise.context.ApplicationScoped;
import javax.faces.annotation.FacesConfig;

@ApplicationScoped
@FacesConfig(version = FacesConfig.Version.JSF_2_3)
public class JSFActivator {

}

現在,一切按預期進行。

解決方案2:

切換至Payara 5.183,即可使用。 無需解決方案1

意見 :為什么玻璃魚會被這樣弄壞。 在如此簡單的工作下,Java EE 8的參考實現應用服務器如何失敗是可悲的。 我希望它現在能從Oracle遷移到Eclipse,從而成為一個難題。

我想在玻璃魚修復之前,我會改用Payara。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM