2011-12-06 2 views
0

는 내 자바 EE 웹 응용 프로그램에서이 주입/JNDI 룩업 오류가 점점 오전 :Java EE NameNotFoundException;

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 

가 확실하지 여기에 붙여 어떤 코드를 알려 감사 주시기 바랍니다.

<?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에 intanties :

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> 
} 

가 여기 내 프로젝트 구조입니다 :

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 클래스의를 여기

내 web.xml에의 :

enter image description here

+0

EJB가 서블릿에 삽입되는 방법과 EJB의 JNDI 바인딩과 관련된 추가 구성 (예 : web.xml)을 확인하는 것이 유용합니다. EJB가 예상되는 JNDI 이름에 바인딩되어 있지 않거나 웹 프로젝트의 참조가 올바르게 구성되지 않았을 가능성이 있습니다. –

+0

안녕하세요, 답장을 보내 주셔서 감사합니다. 나는 web.xml과 액션 클래스를 추가했다. – 0xSina

+0

이 정보는 도움이되지 않습니다. 앞서 언급했듯이 우리는 여러분의 EJB가 서블릿에 어떻게 주입되는지를 볼 필요가있다. 이 코드가 실제로 무엇을하는지 이해하고 있습니까? 자신의 위치를 ​​더 잘 이해하려면 코드입니까? 아니면 다른 누군가의 프로젝트이고 깊이 던져진거야? 또는 당신이 이미 개별적으로 이해하지 못하는 인터넷에서 발견 한 복사 된 미리보기의 전체 자갈 조각입니까? – BalusC

답변

1

좋아, 나는 다음과 같은 수집 할 수 있습니다 제공 한 정보에서 :

  • 당신은 당신은 서블릿있어 글래스 피시
  • 를 사용하고, 4 EJB를
  • 를 주입 OPRSystem.java 패키지 이름은 가증합니다 - 모두 소문자 여야합니다;) 또한 스택 트레이스를 읽기 어렵게 만듭니다 (OPRSystem.OPRSystem은 기괴한 내부 클래스 배열처럼 보입니다)
  • EJB는 @EJB를 사용하여 주입됩니다 (애트리뷰트가 주석에 사용되지 않음)
  • web.xml 파일에 EJB 참조가 없습니다.
  • EJB 인터페이스가 원격입니다.
  • 귀하의 EJB를 (즉, 가정의)
  • 응용 프로그램이 Agent EJB (아마도 다른 사람이 또한 실패를 주입 실패, 이것은 바로 될 수있는 첫 번째 될 일이 같은 EAR에 배포) @Remote 주석 주입 됨)
  • 조회에 실패한 JNDI 이름은 java:comp/env/OPRSystem.OPRSystem/agent입니다. 필드에 @EJB를 사용하여 <fully-qualified name of declaring class>/<field-name>
  • Glassfish EJB FAQ에 따르면 이는 올바른 기준 동일한 FAQ에 따르면 기본 EJB-REF 같이된다 : 대상 EJB 성분이 내에 정의

하면 참조하는 구성 요소가 과 동일한 응용 프로그램이며 과 연결된 원격 인터페이스를 EJB 종속성으로 노출하는 응용 프로그램 내에 목표 EJB 구성 요소 이 하나만 있으면 매핑이 자동으로 수행됩니다. 이 경우 추가 매핑 정보를 지정할 필요가 없습니다.

EJB가 동일한 응용 프로그램에 배포되었는지 확인할 수 있습니까?

그리고 서버 로그에서 올바르게 시작되었다는 증거를 볼 수 있습니까?

+0

예, EJB는 동일한 애플리케이션에 배포됩니다. 내 원래 질문을 확인하고 편집했습니다. – 0xSina

+0

오케이. 'Agent'는 EJB이고'AgentLocal'은'Agent'가 구현 한 (로컬) 인터페이스입니까? 클래스 레벨 주석, 2) 구현하는 인터페이스 클래스, 3) EJB 바인딩 파일 (예 : sun-ejb-jar.xml), 1) –