使用@InjectEJB查找ejb时出现javax.naming.NameNotFoundException

时间:2015-08-27 03:47:17

标签: jpa dependency-injection struts2 ejb-3.0 jndi

我是ejb world的新手......我已经完成了所有配置......但是当我在Struts2 Action类javax.naming.NameNotFoundException中注入EJB时......我正在使用来自googlecode的@InjectEJB。 ..我的ejb和行动课.......

import java.sql.SQLException;

import javax.naming.NamingException;
import javax.persistence.PersistenceException;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ejb3plugin.InjectEJB;

public class LoginAction extends ActionSupport{

    @InjectEJB(name = "LoginDAOin")
    LoginDAOin loginDAO;
    public String execute() throws PersistenceException, SQLException, NamingException{
    loginDAO.validateCredentials("admin", "admin");
        return SUCCESS;
    }

}

DOA

import java.sql.SQLException;
import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.naming.NamingException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceException;
import javax.persistence.Query;

import com.ezakath.Action.LoginDAOin;
import com.ezakath.Exception.ZakathException;
import com.ezakath.Model.ZakathDonor;
import com.ezakath.Util.ErrorCode;

/**
 * Session Bean implementation class LoginDAOEJB
 */

@Local
@Stateless
public class LoginDAOEJB implements LoginDAOin{

    /**
     * Default constructor. 
     */


      @PersistenceContext(unitName="DonorProj", type = PersistenceContextType.EXTENDED)
      private  EntityManager entityManager;


    public LoginDAOEJB() {
        // TODO Auto-generated constructor stub
    }



        Query loginQuery = null;
        List<Donor> donorList = null;


        public boolean validateCredentials(String loginID, String password) {
            boolean validatedResult = false;String status;
            try {
                //Context envCtx = (Context) new InitialContext().lookup("java:jboss/datasources/");
                //System.out.println(envCtx.getNameInNamespace());
                //javax.persistence.EntityManager em1 =  (javax.persistence.EntityManager) envCtx.lookup("eZakath");
                //DataSource ds = (DataSource)ctx.lookup("java:/eDonor");
                ///Connection connection = ds.getConnection();
                //EntityManager entityManager = emf.createEntityManager();
                System.out.println(entityManager);
                donorList = (List<Donor>) entityManager.createQuery("select donor from donor donor").getResultList();
                for(Donor donor:donorList){

                    System.out.println("Donor Details");
                    System.out.println(donor.getFirstName());

                }

            } catch (PersistenceException e) {
                e.printStackTrace();
                throw new Exception(ErrorCode.DatabaseNotConnected,"Cannot open Connetion");
            }
            return validatedResult;

        }



}

本地EJB

import javax.ejb.Local;
import javax.ejb.Remote;

@Local
public interface LoginDAOin {
    boolean validateCredentials(String loginID, String password);
}

日志

08:59:20,533 ERROR [org.apache.struts2.dispatcher.DefaultDispatcherErrorHandler] (http-localhost-127.0.0.1-8080-1) Exception occurred during processing request: LoginDAOin/local -- service jboss.naming.context.java.LoginDAOin.local: javax.naming.NameNotFoundException: LoginDAOin/local -- service jboss.naming.context.java.LoginDAOin.local
    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
    at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)
    at javax.naming.InitialContext.lookup(InitialContext.java:423) [rt.jar:1.7.0]
    at com.opensymphony.xwork2.ejb3plugin.InjectEJBInterceptor.injectEJB(InjectEJBInterceptor.java:103) [struts2ejb3-jboss-plugin-0.0.4.jar:]
    at com.opensymphony.xwork2.ejb3plugin.InjectEJBInterceptor.intercept(InjectEJBInterceptor.java:63) [struts2ejb3-jboss-plugin-0.0.4.jar:]
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:244) [xwork-core-2.3.24.jar:2.3.24]
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) [struts2-core-2.3.24.jar:2.3.24]
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:564) [struts2-core-2.3.24.jar:2.3.24]
    at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81) [struts2-core-2.3.24.jar:2.3.24]
    at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99) [struts2-core-2.3.24.jar:2.3.24]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:801) [vm.jar:1.7.0]

0 个答案:

没有答案