0

Java EE Web アプリケーションから次のインジェクション/JNDI ルックアップ エラーが発生します。

type Exception report

message

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

exception

javax.servlet.ServletException: PWC1392: Error instantiating servlet class OPRSystem.OPRSystem
root cause

com.sun.enterprise.container.common.spi.util.InjectionException: Error creating managed object for class: class OPRSystem.OPRSystem
root cause

com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=OPRSystem.OPRSystem/agent,Remote 3.x interface =AccountManager.Agent,ejb-link=null,lookup=,mappedName=,jndi-name=AccountManager.Agent,refType=Session into class OPRSystem.OPRSystem: Lookup failed for 'java:comp/env/OPRSystem.OPRSystem/agent' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
root cause

javax.naming.NamingException: Lookup failed for 'java:comp/env/OPRSystem.OPRSystem/agent' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=OPRSystem.OPRSystem/agent,Remote 3.x interface =AccountManager.Agent,ejb-link=null,lookup=,mappedName=,jndi-name=AccountManager.Agent,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'AccountManager.Agent#AccountManager.Agent' [Root exception is javax.naming.NamingException: Lookup failed for 'AccountManager.Agent#AccountManager.Agent' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: AccountManager.Agent#AccountManager.Agent not found]]]
root cause

javax.naming.NamingException: Exception resolving Ejb for 'Remote ejb-ref name=OPRSystem.OPRSystem/agent,Remote 3.x interface =AccountManager.Agent,ejb-link=null,lookup=,mappedName=,jndi-name=AccountManager.Agent,refType=Session' .  Actual (possibly internal) Remote JNDI name used for lookup is 'AccountManager.Agent#AccountManager.Agent' [Root exception is javax.naming.NamingException: Lookup failed for 'AccountManager.Agent#AccountManager.Agent' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: AccountManager.Agent#AccountManager.Agent not found]]
root cause

javax.naming.NamingException: Lookup failed for 'AccountManager.Agent#AccountManager.Agent' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: AccountManager.Agent#AccountManager.Agent not found]
root cause

javax.naming.NameNotFoundException: AccountManager.Agent#AccountManager.Agent not found

ここに貼り付けるコードがわからないので、お知らせください。ありがとうございます。

これが私のweb.xmlです:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
    <servlet>
        <servlet-name>OPRSystem</servlet-name>
        <servlet-class>OPRSystem.OPRSystem</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>OPRSystem</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

これは、ejb をインスタンス化する私のアクション クラスです。

package OPRSystem;

import AccountManager.Agent;
import AccountManager.Customer;
import AccountManager.Owner;
import RentalManager.FinancialInstitution;
import javax.servlet.http.HttpServletRequest; 

/**
 *
 * @author ssome
 */
public abstract class Action {
    private final String successpage;
    private final String failpage;
    protected Agent agent;
    protected Customer customer;
    protected Owner owner;
    protected FinancialInstitution fi;

    public Action(String success, String fail) {
        this.successpage = success;
        this.failpage = fail;
    }
    public abstract String perform(HttpServletRequest req);

    /**
     * @return the successpage
     */
    public String getSuccesspage() {
        return successpage;
    }

    /**
     * @return the failpage
     */
    public String getFailpage() {
        return failpage;
    }

    /**
     * @param agent the agent to set
     */
    public void setAgent(Agent agent) {
        this.agent = agent;
    }

    /**
     * @param customer the customer to set
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * @param owner the owner to set
     */
    public void setOwner(Owner owner) {
        this.owner = owner;
    }

    /**
     * @param fi the fi to set
     */
    public void setFi(FinancialInstitution fi) {
        this.fi = fi;
    }

}

ここに私の OPRSystem クラスがあります:

package OPRSystem;

import AccountManager.Agent;
import AccountManager.Customer;
import AccountManager.Owner;
import RentalManager.FinancialInstitution;
import java.io.IOException;
import java.util.HashMap;
import javax.ejb.EJB;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(name="OPRSystem", urlPatterns={"*.do"}) 
public class OPRSystem extends HttpServlet {

    @EJB
    private Agent agent;

    @EJB
    private Customer customer;

    @EJB
    private Owner owner;

    @EJB
    private FinancialInstitution fi;

    private HashMap<String,Action> actions;

    @Override
    public void init() throws ServletException {
        java.util.Date date = new java.util.Date();
        java.sql.Date sqlDate = new java.sql.Date(date.getTime());
        java.sql.Time sqlTime = new java.sql.Time(date.getTime());
        agent.createAdmin(sqlDate, sqlTime);

        actions = new HashMap<String,Action>();
        LoginAction la = new LoginAction("/Welcome.jsp", "/index.jsp");
        la.setAgent(agent);
        la.setCustomer(customer);
        la.setOwner(owner);
        actions.put("login", la);
    }

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        String next = "";
        String op = getOperation(request.getRequestURL());
        Action act = actions.get(op);
        if (act != null) {
            next = act.perform(request);
        }

        // Get the dispatcher
        RequestDispatcher dispatcher =
               getServletContext().getRequestDispatcher(next);


        if (dispatcher != null)
               dispatcher.forward(request, response);
    }

    public String getOperation(StringBuffer requestURL) {
        int lastslash = requestURL.lastIndexOf("/");
        int lastdot = requestURL.lastIndexOf(".");
        String op = requestURL.substring(lastslash+1, lastdot);
        return op;
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

これが私のプロジェクト構造です:

ここに画像の説明を入力

4

1 に答える 1

1

わかりました、あなたが提供した情報から、次の情報を収集できます。

  • Glassfishを使用しています
  • OPRSystem.java4 つの EJB を注入するサーブレットがあります。
  • あなたのパッケージ名は忌まわしいものです - それらはすべて小文字でなければなりません;) また、スタックトレースを読みにくくします (OPRSystem.OPRSystem奇妙な内部クラスの配置のように見えます)
  • EJB は @EJB を使用して注入されます (アノテーションで属性は使用されません)。
  • web.xml ファイルに EJB 参照が含まれていません
  • EJB インターフェースはリモートです (つまり、注釈が付けられています@Remote) 。
  • EJB が同じ EAR にデプロイされている (これは仮定です)
  • アプリケーションが EJBの注入に失敗しています (おそらく他のアプリケーションも失敗するAgentでしょう。たまたま最初に注入されたものです)
  • 検索に失敗した JNDI 名はjava:comp/env/OPRSystem.OPRSystem/agentです。Glassfish EJB FAQによると、これは正しい参照です@EJB。フィールドで 使用する場合のデフォルトの ejb-refは<fully-qualified name of declaring class>/<field-name>
  • 同じFAQによると:

ターゲット EJB コンポーネントが参照元コンポーネントと同じアプリケーション内で定義されていて、アプリケーション内に EJB 依存関係に関連付けられたリモート インターフェースを公開するターゲット EJB コンポーネントが 1 つしかない場合、マッピングは自動的に行われます。この場合、追加のマッピング情報を指定する必要はありません。

EJB が同じアプリケーションにデプロイされていることを確認できますか?

また、サーバー ログでそれらが正しく起動しているという証拠を確認できますか?

于 2011-12-06T10:41:51.843 に答える