EJB 的 jndi语法(在整个调用远程ejb的过程中语法的遵循是相当重要的)
参见jboss-as-quickstarts-7.1.1.CR2\ejb-remote\client\src\main\java\org\jboss\as\quickstarts\ejb\remote\client\RemoteEJBClient.java 中的注释:
<span style="font-size:18px;"><span style="font-size:18px;"> // The JNDI lookup name for a stateless session bean has the syntax of:
// ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>
// <appName> The application name is the name of the EAR that the EJB is deployed in
// (without the .ear). If the EJB JAR is not deployed in an EAR then this is
// blank. The app name can also be specified in the EAR's application.xml
//
// <moduleName> By the default the module name is the name of the EJB JAR file (without the
// .jar suffix). The module name might be overridden in the ejb-jar.xml
//
// <distinctName> : AS7 allows each deployment to have an (optional) distinct name.
// This example does not use this so leave it blank.
//
// <beanName> : The name of the session been to be invoked.
//
// <viewClassName>: The fully qualified classname of the remote interface. Must include
// the whole package name.</span></span>
// The JNDI lookup name for a stateful session bean has the syntax of:
// ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
<span style="font-size:18px;"><span style="font-size:18px;"> //
// <appName> The application name is the name of the EAR that the EJB is deployed in
// (without the .ear). If the EJB JAR is not deployed in an EAR then this is
// blank. The app name can also be specified in the EAR's application.xml
//
// <moduleName> By the default the module name is the name of the EJB JAR file (without the
// .jar suffix). The module name might be overridden in the ejb-jar.xml
//
// <distinctName> : AS7 allows each deployment to have an (optional) distinct name.
// This example does not use this so leave it blank.
//
// <beanName> : The name of the session been to be invoked.
//
// <viewClassName>: The fully qualified classname of the remote interface. Must include
// the whole package name.</span></span>
现在我们对上面的语法进行细化,这是最容易出错的地方!
1. 纯EJB jar部署中的bean的访问
1.1 JNDI lookup name for astatelesssession bean has the syntax of:
<span style="font-size:18px;"><span style="font-size:18px;"><span style="font-size:18px;"> ejb:/<moduleName>/<distinctName>/<beanName>!<viewClassName>
或者
ejb:/<moduleName>/<distinctName>//<beanName>!<viewClassName>
比如:
"ejb:/jboss-as-ejb-remote-app/CounterBean!" + RemoteCounter.class.getName()
"ejb:/jboss-as-ejb-remote-app//CounterBean!" + RemoteCounter.class.getName()</span></span></span>
1.2 JNDI lookup name for astatefullsession bean has the syntax of:
<span style="font-size:18px;"><span style="font-size:18px;">ejb:/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
或者
ejb:/<moduleName>/<distinctName>//<beanName>!<viewClassName>?stateful
比如:
"ejb:/jboss-as-ejb-remote-app/CounterBean!" + RemoteCounter.class.getName()+"?stateful"
"ejb:/jboss-as-ejb-remote-app//CounterBean!" + RemoteCounter.class.getName()+"?stateful"</span></span>
2. 包含在 ear部署中的EJB jar中的bean的访问
2.1 JNDI lookup name for astatelesssession bean has the
syntax of:
<span style="font-size:18px;"><span style="font-size:18px;">ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>
或者
ejb:<appName>/<moduleName>/<distinctName>//<beanName>!<viewClassName>
比如:
"ejb:nms-server-ear/nms-server-ejb/SecuredRemoteSession!" + ISecuredRemoteSession.class.getName()
"ejb:nms-server-ear/nms-server-ejb//SecuredRemoteSession!" + ISecuredRemoteSession.class.getName()
注意: appName 前面没有 斜线 "/"!!! 这是最容易出错的地方!!!
(如果以斜线开头,表明是ejb jar不是在 ear中部署的!!!)</span></span>
2.2 JNDI lookup name for astatefullsession bean has the syntax of:
<span style="font-size:18px;"><span style="font-size:18px;">ejb:<appName>/<moduleName>/<distinctName>/<beanName>!<viewClassName>?stateful
或者
ejb:<appName>/<moduleName>/<distinctName>//<beanName>!<viewClassName>?stateful
注意: <span style="color:#FF0000;">appName 前面没有 斜线 "/"!!! 这是最容易出错的地方!!!</span>
(如果以斜线开头,表明是ejb jar不是在 ear中部署的!!!)</span></span>
总结
看英文文档耐人寻味啊,好好学习英语吧,外网的资料更加的可靠啊!