简体   繁体   English

Ejb3 GlassFish-SerialContext中的JNDI查找失败-NameNotFoundException

[英]Ejb3 GlassFish - JNDI Lookup failed in SerialContext - NameNotFoundException

I'm using EJB3, GlassFish 3.0.1 and eclipse helios 我正在使用EJB3,GlassFish 3.0.1和Eclipse Helios

I have a remote EJB 我有一个远程EJB

@Stateless (mappedName="TestBean")
public class TestBean implements TestBeanRemote {
public int add(int a, int b){
return a+b;
}
}

And the Remote Interface 和远程接口

@Remote
public interface TestBeanRemote {
    public int add(int a, int b);
}

application.xml application.xml中

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" id="Application_ID" version="6">
  <application-name>ear.proj</application-name>
  <display-name>ear.proj</display-name>
  <module>
    <web>
      <web-uri>war.proj</web-uri>
      <context-root>/war</context-root>
    </web>
  </module>
  <module>
    <ejb>ejb.proj.jar</ejb>
  </module>
</application>

I have an empty sun-ejb-jar.xml and I did not define ejb-jar.xml as I read that it's optional since EJB3 I'm putting my EJB in the EAR along with the WEB 我有一个空的sun-ejb-jar.xml,我没有定义ejb-jar.xml,因为我读到它是可选的,因为EJB3我将EJB和WEB放在EAR中

I'm trying to call this EJB in a POJO class 我正在尝试在POJO类中调用此EJB

InitialContext ic = new InitialContext();
ic.lookup("java:global/ear.proj/ejb.proj/TestBean");

I get the following exception javax.naming.NamingException: Lookup failed for java:global/ear.proj/ejb.proj/TestBean' in SerialContext [Root exception is javax.naming.NameNotFoundException: ear.proj] 我收到以下异常javax.naming.NamingException:SerialContext中的java:global / ear.proj / ejb.proj / TestBean'查找失败[根异常是javax.naming.NameNotFoundException:ear.proj]

I guess that the problem is in the EJB setup in my EAR as it's said in the GlassFish EJB FAQ that Each portable global JNDI name is printed out to the server.log during deployment while I can not find any portable keyword in the log 我猜是问题出在我的EAR中的EJB设置中,正如GlassFish EJB FAQ中所说的那样,每个便携式全局JNDI名称在部署期间都打印到了server.log中,而我在日志中找不到任何便携式关键字。

Instead I can see the following INFO: Cannot find module ejb.proj.ejb.jar in application bundle 相反,我可以看到以下信息:在应用程序捆绑包中找不到模块ejb.proj.ejb.jar

Is there something I'm missing? 有什么我想念的吗?

Make sure if you are deploying EJB project, you are notified about this in server.log 确保是否正在部署EJB项目,请在server.log中收到有关此项目的通知

INFO: Portable JNDI names for EJB ${EJB_Name}: 
INFO: Glassfish-specific (Non-portable) JNDI names for EJB ${EJB_Name}:

There you will see context paths. 在那里,您将看到上下文路径。

PS in order to see those logs, depending on configuratoin you may need to change logger settings or even you will be forces to browse through server.log file on server. PS为了查看那些日志,您可能需要更改logger的设置(取决于configuratoin),甚至将server.log浏览服务器上的server.log文件。

Try to use: 尝试使用:

ic.lookup("java:global/*classesdirectory*/TestBean");

where classesdirectory = the directory which contains the classes(TestBean.class) in your project tree in Eclipse. 其中classesdirectory =在Eclipse中的项目树中包含类(TestBean.class)的目录。

In Netbeans you can try 在Netbeans中,您可以尝试

ic.lookup("java:global/classes/TestBean");

because the compile classe (even package and subpackage ar) 因为编译类(甚至包和子包ar)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM