EJB Remote/Local 绑定和JNDI Lookup
从同事那里学到一种方便的注解SessionBean的方式。代码我放到github去了 https://github.com/EdisonXu/Test/commit/703d49123dca9e666269771b08cc45dea6bff616 或者直接看路径 https://github.com/EdisonXu/Test/tree/master/remote-bean-test其中test-local虽然打成了可执行jar包,但是依然无法直接通过Java -jar去执行。因为缺乏jboss相关依赖的包。我在网上没找到dependency,所以懒得搞了。直接把本地JBoss的包配到buildPath了,直接在eclipse中运行。关键有两点:1. 定义一个interface文件:public interface RemoteTest { public static final String NAME = "Test/RemoteTest"; public static final String JNDI_NAME = "Test/RemoteTest/remote"; public String getTest(); /** * Local interface for session bean */ public static interface Local extends RemoteTest{} /** * Remote interface for session bean */ public static interface Remote extends RemoteTest{}}这样在注入的时候直接@EJBRemoteTest.Local localRemoteTest;或者@EJBRemoteTest.Remote RemoteTest;值得注意的是,如果这里直接用 RemoteTest 去作为类型,在加载这个包时会报错,会提示定义的RemoteTest.NAME的值,即Test/RemoteTest不唯一。导致部署失败。2. 方便的JNDI Lookupejb3.1支持的几种JNDI LOOKUP:java:global/Get EJB instance by lookup global in java: Namespace. Syntax: java:global/<ear-name>/<jar-name>/<bean-name>[!<fully-qualified-interface-name>] Sample: SampleBean implements SampleBeanRemote interface SampleBeanRemote { JNDI_NAME="SampleBean";}sampleBeanInstance = (SampleBeanRemote)lookupByGlobal(SampleBeanLocal.JNDI_NAME);java:app/Get EJB instance by lookup app in java: Namespace. Note: Only effect when the expect bean is in the same ear file with the POJO calling this method. Syntax: java:app/<jar-name>/<bean-name>[!<fully-qualified-interface-name>] Sample: SampleBean implements SampleBeanLocal interface SampleBeanLocal { NAME="SampleBean";}sampleBeanInstance = (SampleBeanLocal)lookupByApp(SampleBeanLocal.NAME);java:module/Get EJB instance by lookup module in java: Namespace. Note: Only effect when the expect bean is in the same jar file with the POJO calling this method. Syntax: java:module/<bean-name>[!<fully-qualified-interface-name>] Sample: SampleBean implements SampleBeanLocal SampleBeanLocal { NAME="SampleBean";}sampleBeanInstance = (SampleBeanLocal)lookupByModule(SampleBeanLocal.NAME);其中global, app 需要提供包名,但有时候我们会在包名里面包含版本号,这样每次修改都要去改源代码,很不方便。而用上面提供的REMOTE/LOCAL绑定方式,现在直接用RemoteTest rt = (RemoteTest)ctx.lookup(RemoteTest.JNDI_NAME);方便快捷。另外,还有一种方式是在jar包里面添加ejb-jar.xml。里面显示的把去掉版本后的包名或别名写到 <moduleName>中去。这样用包名或别名替换掉原来带版本号的包名就行了。
---------------------
作者:Edison徐
来源:CSDN
原文:https://blog.csdn.net/xeseo/article/details/9467173
版权声明:本文为博主原创文章,转载请附上博文链接!
EJB Remote/Local 绑定和JNDI Lookup的更多相关文章
- Ejb: remote调用
用的是wildfly 9.0.2 一:在myeclipse中新建wildfly 9.0.2的server(如何新建去网上搜) 二:修改wildfly server的argument(在run conf ...
- 绑定的jndi获得connection时,出的错,java.io.NotSerializableException
求助:java.io.NotSerializableException 最近系统频繁出现Lookup error: java.io.WriteAbortedException: Writing abo ...
- Class loading in JBoss AS 7--官方文档
Class loading in AS7 is considerably different to previous versions of JBoss AS. Class loading is ba ...
- java集群技术(转)
来源:http://blog.csdn.net/cdh1213/article/details/21443239 序言 越来越多的关键应用运行在J2EE(Java2, Enterprise Editi ...
- 2015第44周五Java集群技术(转)
从http://blog.csdn.net/cdh1213/article/details/21443239上看到这篇文章,感觉很不错,找好久没找到中文出处,最早看是从http://www.these ...
- 深入了解java集群技术
原文源自:http://blog.csdn.net/happyangelling/article/details/6413584 序言 越来越多的关键应用运行在J2EE(Java 2, Enterpr ...
- java集群
java集群 分类: java学习2011-05-12 09:12 7531人阅读 评论(9) 收藏 举报 java服务器负载均衡ejb集群数据库 序言 越来越多的关键应用运行在J2EE(Java 2 ...
- java集群技术
序言 越来越多的关键应用运行在J2EE(Java 2, Enterprise Edition)中,这些诸如银行系统和账单处理系统需要高的可用性(High Availability, HA),同时像Go ...
- java集群技术(转)
序言 越来越多的关键应用运行在J2EE(Java 2, Enterprise Edition)中,这些诸如银行系统和账单处理系统需要高的可用性(High Availability, HA),同时像Go ...
随机推荐
- koa-router post请求接收的参数为空
注:koa-router路由和koa-bodyparser中间件 post请求中参数为空. 页面代码 <!DOCTYPE html> <html> <head> ...
- java-数组连接的几种方式
多个数组进行拼接, 1, 使用java自己的 System#arrayCopy() byte[] message = new byte[heads.length + result.length + b ...
- 你真的理解编码吗?unicode,utf8,utf16详解
背景 前两天在网上看到一篇关于编码的讨论,仔细学习了一下unicode,utf8,utf16的定义.这篇博客旨在让读者真正理解他们是什么. 什么是编码 在阅读本文之前建议读者先去阅读这篇文章:http ...
- vi/vim编辑器必知必会
一.我们为什么要学习vim编辑器? Linux的命令行界面下面有非常多的文本编辑器.比如经常听说的就有Emacs.pico.nano.joe与vim等.vim可以看做是vi的高级版.我们为什么一定要学 ...
- linux-openvpn
1.安装openvpn 1)安装需要的依赖,需要用到epel源 #yum -y install epel-release 修改epel.repo文件enabled=1 #yum install ea ...
- 线程池ThreadPoolExecutor的一种扩展办法
概述 在JAVA的世界里,如果想并行的执行一些任务,可以使用ThreadPoolExecutor. 大部分情况下直接使用ThreadPoolExecutor就可以满足要求了,但是在某些场景下,比如瞬时 ...
- 【angular5项目积累总结】侧栏菜单 navmenu
View Code import { Component, OnInit } from '@angular/core'; import { HttpClient } from '@angular/co ...
- [转]Easily Add a Ribbon into a WinForms Application
本文转自:https://www.codeproject.com/articles/364272/easily-add-a-ribbon-into-a-winforms-application-cs ...
- 【手记】解决Resharper 2018.x起本机license server不能用的问题
ReSharper升级到2018版后,一直用的好好的本机license server(下称LS)不能用了,报The license server address is incorrect....在网上 ...
- 【ZeroMQ】1、ZeroMQ(java)入门之Requerst/Response模式
自己最开始是在cloud foundry中接触过消息服务器(nats),或者说是消息中间件,也算是初步知道了一个消息服务器对于分布式的网络系统的重要性,后来自己也曾想过在一些项目中使用它,尤其是在一些 ...