InitialContext ctx = new InitialContext();
String jndiName = "java:global/EJBExample/HelloEjbBean!huizhi.HelloEjbBeanLocal";
Object o = ctx.lookup(jndiName);java
获取到的竟然是HelloEjbBeanLocal$$$View2的proxy代理对象。服务器
这该如何转换成HelloEjbBeanLocal接口呢?app
原来配置不正确。运维
Jboss7获取jndi方式与以前版本彻底不同,使用了新技术实现。请看原文说法:dom
Previous versions of JBoss AS (versions < 7.x) used JNP project asthe JNDI naming implementation. Developers of client applications of previousversions of JBoss AS will be familiar with the jnp:// PROVIDER_URL URL theyused to use in their applications for communicating with the JNDI server on theJBoss server.ide
Starting AS7, the JNP project is not used. Neither on the server sidenor on the client side. The client side of the JNP project has now beenreplaced by jboss-remote-naming project. There were various reasons why the JNPclient was replaced by jboss-remote-naming project. One of them was the JNPproject did not allow fine grained security configurations while communicatingwith the JNDI server. The jboss-remote-naming project is backed by thejboss-remoting project which allows much more and better control over security.ui
<subsystem xmlns="urn:jboss:domain:naming:1.1">spa
<bindings>.net
<lookup name="AdminEjb/local" lookup="ejb:/admin_ejb/AdminEjb!com.mipt.admin.ifc.AdminIfc"/>代理
</bindings>
</subsystem>
此方式配置简单,不用修改代码,但须要重启服务器才生效。
主要是配置<lookup/>,name可自定义简称,根据name能找到真正的jndi,而后返回对应的ejb实例。
若不须要更改原来项目中获取方式的代码,只须要把name改为对应的AdminEjb/local便可。
Lookup的值为实际jndi路径,命名规则以下:
JNDI: ejb:appName /moduleName/distinctName/beanName!viewClassName
appName:这里是.EAR包的名称,若是你打包成JAR发布的话,这里则留空
moduleName:表示模块名,也就是ejb包名,但不包括后缀.jar,如admin_ejb.jar。moduleName为admin_ejb
distinctName:若是没有定义其更详细的名称,则这里留空
beanName:这里为实现类的名称
viewClassName:为接口全路径名称
缺点:在standalone.xml绑定jndi的话,上线时运维人员需手动添加绑定,使用不方便。
以前接口代码中通常会把jndi以静态变量定义,如:adminIfc中的
public static final Java.lang.Stringjndi = “AdminEjb/local”
如今只须把变量值更改成jndi = “ejb:/admin_ejb/AdminEjb!com.mipt.admin.ifc.AdminIfc”便可.