首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 服务器 > 其他服务器 >

EJB3 部署在JBoss5.0.0-GA上,客户端调用报错误

2012-02-03 
EJB3 部署在JBoss5.0.0-GA上,客户端调用报异常。EJB3的代码:package communicateMgmtimport javax.ejb.Sta

EJB3 部署在JBoss5.0.0-GA上,客户端调用报异常。
EJB3的代码:

package communicateMgmt;

import javax.ejb.Stateless;

@Stateless
public class CommunicateBean implements CommunicateBeanLocal,
CommunicateBeanRemote {

public void queryParameter() {
System.out.println("Query Parameter");
}
}

package communicateMgmt;

import javax.ejb.Remote;

@Remote
public interface CommunicateBeanRemote {

public void queryParameter();

}

JBoss启动后显示:
12:22:28,375 INFO [JBossASKernel] Created KernelDeployment for: CommunicateEJB.jar
12:22:28,375 INFO [JBossASKernel] installing bean: jboss.j2ee:jar=CommunicateEJB.jar,name=CommunicateBean,service=EJB3
12:22:28,375 INFO [JBossASKernel] with dependencies:
12:22:28,375 INFO [JBossASKernel] and demands:
12:22:28,375 INFO [JBossASKernel] jboss.ejb:service=EJBTimerService
12:22:28,375 INFO [JBossASKernel] and supplies:
12:22:28,375 INFO [JBossASKernel] jndi:CommunicateBean/remote
12:22:28,375 INFO [JBossASKernel] Class:communicateMgmt.CommunicateBeanLocal
12:22:28,375 INFO [JBossASKernel] jndi:CommunicateBean/remote-communicateMgmt.CommunicateBeanRemote
12:22:28,375 INFO [JBossASKernel] jndi:CommunicateBean/local-communicateMgmt.CommunicateBeanLocal
12:22:28,390 INFO [JBossASKernel] jndi:CommunicateBean/local
12:22:28,390 INFO [JBossASKernel] Class:communicateMgmt.CommunicateBeanRemote
12:22:28,390 INFO [JBossASKernel] Added bean(jboss.j2ee:jar=CommunicateEJB.jar,
name=CommunicateBean,service=EJB3) to KernelDeployment of: CommunicateEJB.jar
12:22:28,843 INFO [SessionSpecContainer] Starting jboss.j2ee:jar=CommunicateEJB.jar,name=CommunicateBean,service=EJB3
12:22:28,875 INFO [EJBContainer] STARTED EJB: communicateMgmt.CommunicateBean ejbName: CommunicateBean
12:22:29,046 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:

  CommunicateBean/remote - EJB3.x Default Remote Business Interface
  CommunicateBean/remote-communicateMgmt.CommunicateBeanRemote - EJB3.x Remote Business Interface
  CommunicateBean/local - EJB3.x Default Local Business Interface
  CommunicateBean/local-communicateMgmt.CommunicateBeanLocal - EJB3.x Local Business Interface

12:22:29,218 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8
080
12:22:29,250 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
12:22:29,265 INFO [ServerImpl] JBoss (Microcontainer) [5.0.0.GA (build: SVNTag=
JBoss_5_0_0_GA date=200812042120)] Started in 54s:265ms

客户端代码:
  System.out.println("EJB begin");
  Properties prop = new Properties();
  prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
  prop.put(Context.PROVIDER_URL, "localhost:1099");
  prop.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
  Context ctx = new InitialContext(prop);
  CommunicateBeanRemote objref = (CommunicateBeanRemote)ctx.lookup("CommunicateBean/remote");
  objref.queryParameter();

执行上面客户端代码后,显示异常:
EJB begin
java.lang.ClassCastException: javax.naming.Reference cannot be cast to communicateMgmt.CommunicateBeanRemote
at service.impls.DeviceManagerImpl.addDevice(DeviceManagerImpl.java:59)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
  ...


[解决办法]
Properties prop = new Properties();


prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
prop.setProperty(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
prop.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");

IUserManageBusRemote r = (IUserManageBusRemote)ctx.lookup("java:/SealineZCornerBusinessSystem/UserManageBusImpl/remote");

SealineZCornerBusinessSystem.ear

最好在部署的时候打包成ear;
在jboss5直接jar部署时你定义的bean是全局范围的!
[解决办法]
我也遇到这个问题,不知道怎么回事.....

热点排行