ejb查找时javax.naming.NameNotFoundException

时间:2015-07-28 13:12:32

标签: java jboss ejb

我正在将一个ejb应用程序从weblogic迁移到jboss。该应用程序正在使用jndi寻找ejb。我将ejb-jar.xml和jboss.xml放到WEB-INF /中,如下所示

的jboss.xml

<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 4.0//EN"
   "http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd">

<jboss>
    <enterprise-beans>
        <session>
            <ejb-name>DataAccessEJB</ejb-name>
            <jndi-name>HeatMapDataAccessJNDI</jndi-name>
            <local-jndi-name>HeatMapDataAccessLocalJNDI</local-jndi-name>
        </session>
        <session>
            <ejb-name>PMSessionFacadeEJB</ejb-name>
            <jndi-name>PMSessionFacadeJNDI</jndi-name>
            <local-jndi-name>PMSessionFacadeLocalJNDI</local-jndi-name>
        </session>
        <session>
            <ejb-name>RRMSessionFacadeEJB</ejb-name>
            <jndi-name>RRMSessionFacadeJNDI</jndi-name>
            <local-jndi-name>RRMSessionFacadeLocalJNDI</local-jndi-name>
        </session>
        <session>
            <ejb-name>FIPMSessionFacadeEJB</ejb-name>
            <jndi-name>FIPMSessionFacadeJNDI</jndi-name>
            <local-jndi-name>FIPMSessionFacadeLocalJNDI</local-jndi-name>
        </session>              
    </enterprise-beans>
</jboss>

ejb-jar.xml中

<?xml version="1.0"?>
<!DOCTYPE ejb-jar PUBLIC
"-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
    <enterprise-beans>
    <!-- A list of all the session and entity beans packaged within this jar file. -->
        <session>
            <!-- An arbitrary identifier that's used to match up this description of the bean with the
         corresponding entry in the weblogic-ejb-jar.xml file -->
            <ejb-name>
        DataAccessEJB
            </ejb-name>

            <!-- The name of the interface implemented by the bean's home object -->
            <home>
        com.bfm.app.pirptfe.heatmap.ejb.DataAccessHomeInterface
            </home>

            <!-- The name of the interface implemented by the bean's remote object -->
            <remote>
        com.bfm.app.pirptfe.heatmap.ejb.DataAccessRemoteInterface
            </remote>
            <local-home>
                com.bfm.app.pirptfe.heatmap.ejb.DataAccessLocalHomeInterface
            </local-home>
            <local>
                com.bfm.app.pirptfe.heatmap.ejb.DataAccessLocalInterface
            </local>
            <!-- The name of the bean class -->
            <ejb-class>
        com.bfm.app.pirptfe.heatmap.ejb.DataAccessBean
            </ejb-class>

            <!-- Is this session bean Stateful or Stateless? -->
            <session-type>
        Stateless
            </session-type>

            <!-- If this bean uses any transactions, will these transactions be managed by the Container or
         by the Bean itself? -->
            <transaction-type>
        Container
            </transaction-type>
    </session>

        <session>
            <ejb-name>
        PMSessionFacadeEJB
            </ejb-name>
            <home>
        com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
            </home>
            <remote>
        com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
            </remote>
            <ejb-class>
        com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeBean
            </ejb-class>
            <session-type>
        Stateless
            </session-type>
            <transaction-type>
        Container
            </transaction-type>     
        </session>
        <session>
            <ejb-name>
        RRMSessionFacadeEJB
            </ejb-name>
            <home>
        com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeHome
            </home>
            <remote>
        com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeRemote
            </remote>
            <ejb-class>
        com.bfm.app.pirptfe.heatmap.ejb.RRMSessionFacadeBean
            </ejb-class>
            <session-type>
        Stateless
            </session-type>
            <transaction-type>
        Container
            </transaction-type>     
        </session>     
        <session>
            <ejb-name>
        FIPMSessionFacadeEJB
            </ejb-name>
            <home>
        com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
            </home>
            <remote>
        com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
            </remote>
            <ejb-class>
        com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeBean
            </ejb-class>
            <session-type>
        Stateless
            </session-type>
            <transaction-type>
        Container
            </transaction-type>     
        </session>   
    </enterprise-beans>
</ejb-jar>

当我运行我的应用程序时,它会加载。日志如下所示

14:08:16,990 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named FIPMSessionFacadeEJB in deployment unit deployment "pirptfe.war" are as follows:

    java:global/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
    java:app/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
    java:module/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
    java:jboss/exported/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeRemote
    java:global/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
    java:app/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
    java:module/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome
    java:jboss/exported/pirptfe/FIPMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.FIPMSessionFacadeHome

用于查找服务的JNDI名称如下所示

// The JNDI Names used to lookup a service
private static final String PMSESSIONFACADEEJB_JNDIHOME   =
        "PMSessionFacadeJNDI";
private static final String RRMSESSIONFACADEEJB_JNDIHOME  =
        "RRMSessionFacadeJNDI";
private static final String FIPMSESSIONFACADEEJB_JNDIHOME =
        "FIPMSessionFacadeJNDI";

当代码尝试使用下面的代码在上下文中查找ejb时,它会给出异常

serviceName是以下代码中的JNDI名称

public EJBHome getEJBHome(int parServiceId)
                   throws FrontServiceLocatorException {

    // Trying to find the JNDI Name for the reqested service
    String  serviceName = getServiceName(parServiceId);
    EJBHome ejbHome = null;
    try {

        // Checking to see if I can find the EJBHome interface in the cache
        if (ejbHomeCashe_.containsKey(serviceName)) {
            ejbHome = (EJBHome)ejbHomeCashe_.get(serviceName);
            return ejbHome;
        } else {

            // I could not find the home interface in the cache, look it up
            // and then cache it
            Context ctx         = new InitialContext();
            Object  jndiRef     = ctx.lookup(serviceName);
            Object  portableObj = PortableRemoteObject.narrow(jndiRef,
                                                              getEJBHomeRef(
                                                                      parServiceId));
            ejbHome = (EJBHome)portableObj;
            ejbHomeCashe_.put(serviceName, ejbHome);
            return ejbHome;
        }
    } catch (NamingException e) {
        throw new FrontServiceLocatorException("Naming exception error in FrontServiceLocator.getEJBHome()",
                                               e);
    }
     catch (Exception e) {
        throw new FrontServiceLocatorException("General exception in FrontServiceLocator.getEJBHome()",
                                               e);
    }
}

例外:

18:40:12,376 ERROR [stderr] (http-localhost-127.0.0.1-8080-1) javax.naming.NameNotFoundException: RRMSessionFacadeJNDI -- service jboss.naming.context.java.RRMSessionFacadeJNDI

18:40:12,376 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)

18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)

18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.InitialContext.lookup(InitialContext.java:113)

18:40:12,392 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:214)

18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at javax.naming.InitialContext.lookup(InitialContext.java:411)

18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.FrontServiceLocator.getEJBHome(FrontServiceLocator.java:191)

18:40:12,407 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.CommonalityRRM.process(CommonalityRRM.java:77)

18:40:12,423 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at com.bfm.app.pirptfe.heatmap.web.CommonalityRRM.doPost(CommonalityRRM.java:54)

18:40:12,423 ERROR [stderr] (http-localhost-127.0.0.1-8080-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

有人可以帮我解决。

1 个答案:

答案 0 :(得分:0)

我的问题尚未解决,但我得到的答案是我在这里做错了。

  1. 我们必须使用jboss-ejb3.xml而不是jboss.xml重命名该文件
  2. 我们可以使用jboss-ejb3.xml
  3. 覆盖我们的ejb-jar.xml

    的JBoss-ejb3.xml

    &#13;
    &#13;
    <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:s="urn:security"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd
                         http://java.sun.com/xml/ns/javaee"
        version="3.1" impl-version="2.0">
        <enterprise-beans>
    		<session>
    			<ejb-name>DataAccessEJB</ejb-name>
    			<resource-ref>
    			    <res-ref-name>java:app/pirptfe/HeatMapDataAccessJNDI</res-ref-name>
    			    <lookup-name>HeatMapDataAccessJNDI</lookup-name>
    			</resource-ref>
    		</session>
    		<session>
    			<ejb-name>PMSessionFacadeEJB</ejb-name>
    			<resource-ref>
    			   <res-ref-name>java:app/pirptfe/PMSessionFacadeJNDI</res-ref-name>
    			   <lookup-name>PMSessionFacadeJNDI</lookup-name>
    			</resource-ref>
    		</session>
    		<session>
    			<ejb-name>RRMSessionFacadeEJB</ejb-name>
    			<resource-ref>
    			   <res-ref-name>java:app/pirptfe/RRMSessionFacadeJNDI</res-ref-name>
    			   <lookup-name>RRMSessionFacadeJNDI</lookup-name>
    			</resource-ref>
    		</session>
    		<session>
    			<ejb-name>FIPMSessionFacadeEJB</ejb-name>
    			<resource-ref>
    			   <res-ref-name>java:app/pirptfe/FIPMSessionFacadeJNDI</res-ref-name>
    			   <lookup-name>FIPMSessionFacadeJNDI</lookup-name>
    			</resource-ref>
    		</session>
        </enterprise-beans>
    </jboss:ejb-jar>
    &#13;
    &#13;
    &#13;

    现在我收到以下错误消息

    &#13;
    &#13;
    17:32:34,629 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-1) JNDI bindings for session bean named PMSessionFacadeEJB in deployment unit deployment "pirptfe.war" are as follows:
    
    	java:global/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
    	java:app/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
    	java:module/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
    	java:jboss/exported/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeHome
    	java:global/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
    	java:app/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
    	java:module/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
    	java:jboss/exported/pirptfe/PMSessionFacadeEJB!com.bfm.app.pirptfe.heatmap.ejb.PMSessionFacadeRemote
    
    17:32:35,787 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS015870: Deploy of deployment "pirptfe.war" was rolled back with failure message {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.app.pirptfe.pirptfe.FIPMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.FIPMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.FIPMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.FIPMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.PMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.PMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.PMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.PMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.RRMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.RRMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.RRMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.RRMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.HeatMapDataAccessJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.HeatMapDataAccessJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.HeatMapDataAccessJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.HeatMapDataAccessJNDI]"]}
    17:32:37,552 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015877: Stopped deployment pirptfe.war in 1773ms
    17:32:37,553 INFO  [org.jboss.as.controller] (DeploymentScanner-threads - 2) JBAS014774: Service status report
    JBAS014775:    New missing/unsatisfied dependencies:
          service jboss.naming.context.java.module.pirptfe.pirptfe.env.FIPMSessionFacadeJNDI (missing) dependents: [service jboss.naming.context.java.app.pirptfe.pirptfe.FIPMSessionFacadeJNDI] 
          service jboss.naming.context.java.module.pirptfe.pirptfe.env.HeatMapDataAccessJNDI (missing) dependents: [service jboss.naming.context.java.app.pirptfe.pirptfe.HeatMapDataAccessJNDI] 
          service jboss.naming.context.java.module.pirptfe.pirptfe.env.PMSessionFacadeJNDI (missing) dependents: [service jboss.naming.context.java.app.pirptfe.pirptfe.PMSessionFacadeJNDI] 
          service jboss.naming.context.java.module.pirptfe.pirptfe.env.RRMSessionFacadeJNDI (missing) dependents: [service jboss.naming.context.java.app.pirptfe.pirptfe.RRMSessionFacadeJNDI] 
    
    17:32:37,584 ERROR [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) {"JBAS014653: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-2" => {"JBAS014771: Services with missing/unavailable dependencies" => ["jboss.naming.context.java.app.pirptfe.pirptfe.FIPMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.FIPMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.FIPMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.FIPMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.PMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.PMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.PMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.PMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.RRMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.RRMSessionFacadeJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.RRMSessionFacadeJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.RRMSessionFacadeJNDI]","jboss.naming.context.java.app.pirptfe.pirptfe.HeatMapDataAccessJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.HeatMapDataAccessJNDIMissing[jboss.naming.context.java.app.pirptfe.pirptfe.HeatMapDataAccessJNDIjboss.naming.context.java.module.pirptfe.pirptfe.env.HeatMapDataAccessJNDI]"]}}}
    &#13;
    &#13;
    &#13;