Jboss as 7 获取ejb3 local接口 获取到的是Proxy,jndi配置ejb:正常

InitialContext ctx = new InitialContext();
String jndiName = "java:global/EJBExample/HelloEjbBean!huizhi.HelloEjbBeanLocal";
Object o = ctx.lookup(jndiName);

获取到的居然是HelloEjbBeanLocal$$$View2的proxy代理对象。

这该如何转换成HelloEjbBeanLocal接口呢?

原来配置不正确。

Jboss7获取jndi方式与之前版本完全不一样,使用了新技术实现。请看原文说法:

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.

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.

 

3.1    绑定jndi方式

<subsystem xmlns="urn:jboss:domain:naming:1.1">

   <bindings>

     <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的话,上线时运维人员需手动添加绑定,使用不方便。

3.2    代码定义jndi

之前接口代码中一般会把jndi以静态变量定义,如:adminIfc中的

public static final Java.lang.Stringjndi = “AdminEjb/local”

现在只须把变量值更改为jndi = “ejb:/admin_ejb/AdminEjb!com.mipt.admin.ifc.AdminIfc”即可.

转载于:https://my.oschina.net/u/151615/blog/781268

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值