1

次のように、ejb ステートフル セッション Bean コードを呼び出すサーブレット コードがあります。

public class UsesBeansSF extends HttpServlet {   
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
          // do something
       }

    finally {}
 } 

private SessionBeanSFRemote lookupSessionBeanSFRemote() {
    try {
        Context c = new InitialContext();
        return (SessionBeanSFRemote) c.lookup("java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote");
    } catch (NamingException ne) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
        throw new RuntimeException(ne);
    }
}

}

このコードは、* マークの間に線がなくてもうまく機能します。ただし、SessionBeanSFRemote sessionBeanSF = lookupSessionBeanSFRemote()この行を追加すると (ステートフル セッション Bean を呼び出すことを意味します)、コードでエラーが発生します。実際には、何らかのジョブを実行するためにステートレス セッション Bean を呼び出す必要があります。なぜそれが起こっているのか誰でも私を助けることができますか? 前もって感謝します。

エラーメッセージは次のとおりです。

タイプ例外報告メッセージ

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

例外

javax.servlet.ServletException: PWC1392: Error instantiating servlet class websSF.comsSF.UsesBeansSF

根本的な原因

com.sun.enterprise.container.common.spi.util.InjectionException: 
         Error creating managed object for class websSF.comsSF.UsesBeansSF

根本的な原因

java.lang.reflect.InvocationTargetException

根本的な原因

java.lang.RuntimeException: javax.naming.NamingException: 
Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext  
[Root exception is javax.naming.NamingException: 
ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]]

根本的な原因

javax.naming.NamingException: 
Lookup failed for 'java:global/MyEJBSF/SessionBeanSF!ejbSF.SessionBeanSFRemote' in SerialContext  
[Root exception is javax.naming.NamingException: 
ejb ref resolution error for remote business interfaceejbSF.SessionBeanSFRemote
[Root exception is java.lang.NullPointerException]]

根本的な原因

javax.naming.NamingException: ejb ref resolution error for remote business 
interfaceejbSF.SessionBeanSFRemote [Root exception is java.lang.NullPointerException]

根本的な原因

java.lang.NullPointerException
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.0.1 logs.

サーバー: GlassFish サーバー オープン ソース エディション 3.0.1

4

1 に答える 1

3

ステートフルBeanを適切に設定したかどうかはわかりません。あなたはこれを試すことができます:

@Stateful(mappedName = "ejb/myStatefulBean")
public class MyStatefulBean implements MyStatefulRemoteInterface {
   // Your implementation
}

次に、次のように検索できます。

InitialContext context = new InitialContext();
MyStatefulRemoteInterface myStatefulBean = (MyStatefulRemoteInterface) context.lookup("ejb/myStatefulBean");

さらに、このステートフルBeanは、再利用するために各クライアントのセッションに保存する必要があります。

HttpSession clientSession = request.getSession(false);
clientSession.setAttribute("myStatefulBean", myStatefulBean);

今後のリクエストでは、クライアントのセッションからBeanを取得してから、クライアントの新しいセッションを作成することができます。

于 2012-01-01T11:35:12.243 に答える