关于jbuilder5和weblogic6.1联合开发ejb的问题。

The_east_key 2002-04-01 10:46:25
大家好,我在用jbuilder开发ejb的时候,根据http://www.yesky.com/20020116/214231.shtml做了,现在用客户测试的时候,总是出现一些问题,请指教;
------------------------------------------------------------------------
代码如下:
package quickstart;
import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
public class Client {
private TellerHome tellerHome = null;
//*************************************************************
// Client client = new Client();
//*************************************************************

/**Construct the EJB test client*/
public Client() {
try {
//get naming context
Context ctx = getInitialContext();
//look up jndi name
Object ref = ctx.lookup("TellerHome");
//cast to Home interface
tellerHome = (TellerHome) PortableRemoteObject.narrow(ref, TellerHome.class);
Teller teller=tellerHome.create();
String str=teller.getDefaultStr();
System.out.println(str);
}
catch(Exception e) {
e.printStackTrace();
}
}
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}

return new InitialContext(properties);
}
catch(Exception e) {
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
}

//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------

public TellerHome getHome() {
return tellerHome;
}
/**Main method*/

public static void main(String[] args) {
Client client = new Client();
// Use the getHome() method of the client object to call Home interface
// methods that will return a Remote interface reference. Then
// use that Remote interface reference to access the EJB.
}
}

----------------------------------------------------------------------
问题1:
请注意
//*************************************************************
// Client client = new Client();
//*************************************************************
当此行被注释掉的时候,出现如下错误:
javax.naming.NameNotFoundException: Unable to resolve TellerHome. Resolved: '' Unresolved:'TellerHome' ; remaining name ''
当此行有效的时候:
ava.lang.StackOverflowError
at quickstart.Client.<init>(Client.java:9)
at quickstart.Client.<init>(Client.java:9)
现在我已经试了很多次了,还是不能成功,谢谢大家指教。

...全文
8 点赞 收藏 11
写回复
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
zwhhwz 2002-04-10
你的EJB应该是没有DEPLOY成功,重新DEPLOY一下,选择REDEPLOY
回复
鹏源雪峰 2002-04-10
我在jbuild6也看过一次这样的问题,但代码不可能有错的,所以真的很奇怪的
回复
The_east_key 2002-04-10
已经发布上去了 。所以很奇怪。
回复
uu_snow 2002-04-10
你的EJB发布过吗?
回复
The_east_key 2002-04-08
--------------------------------------------------------------
TellerHome.java的原代码:
package quickstart;

import java.rmi.*;
import javax.ejb.*;

public interface TellerHome extends EJBHome {
public Teller create() throws RemoteException, CreateException;
}
********************************************************************
TellerBean.java的原代码:
package quickstart;

import java.rmi.*;
import javax.ejb.*;

public class TellerBean implements SessionBean {
private SessionContext sessionContext;
public void ejbCreate() {
}
public void ejbRemove() throws RemoteException {
}
public void ejbActivate() throws RemoteException {
}
public void ejbPassivate() throws RemoteException {
}
public void setSessionContext(SessionContext sessionContext) throws RemoteException {
this.sessionContext = sessionContext;
}

public String getDefaultStr()
{
return "Hello,this is a examples made by sunxiaoming!";
}
}
**************************************************************
Teller.java
package quickstart;

import java.rmi.*;
import javax.ejb.*;

public interface Teller extends EJBObject {
public java.lang.String getDefaultStr() throws RemoteException;
}
****************************************************************
Client.java
package quickstart;

import javax.naming.*;
import java.util.Properties;
import javax.rmi.PortableRemoteObject;
import quickstart.TellerBean;


public class Client {
private TellerHome tellerHome = null;
// Client client = new Client();
/**Construct the EJB test client*/
public Client() {
try {
//get naming context
Context ctx = getInitialContext();
//look up jndi name
Object ref = ctx.lookup("TellerHome");
//cast to Home interface
tellerHome = (TellerHome) PortableRemoteObject.narrow(ref, TellerHome.class);
// Teller teller=tellerHome.create();
// String str=teller.getDefaultStr();
// System.out.println(str);
}
catch(Exception e) {
e.printStackTrace();
}
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
}
return new InitialContext(properties);
}
catch(Exception e) {
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
}
//----------------------------------------------------------------------------
// Utility Methods
//----------------------------------------------------------------------------
public TellerHome getHome() {
return tellerHome;
}
/**Main method*/
public static void main(String[] args) {
Client client = new Client();
// Use the getHome() method of the client object to call Home interface
// methods that will return a Remote interface reference. Then
// use that Remote interface reference to access the EJB.
}
private void jbInit() throws Exception {
}
}
****************************************************************

回复
biosun 2002-04-04
我出遇到同样的问题!但好像同样的EJB在Jbuilder5.0+WebLogic6.1下就不会出现这样的问题。
回复
merry_xin 2002-04-03
把ejb的所有代码,加上来,我看看。
回复
The_east_key 2002-04-03
还是不行,我应该怎么做?Please help me!
回复
zhipop 2002-04-01
没有把这个TellerHome类包含进去,所以不能调用方法

看看是不是,应该 import TellerHome;
回复
zhipop 2002-04-01
看问题好象TellerHome出什么问题了
其他应该没有什么问题,你实例化的时候好象出问题的
回复
zhiweihua 2002-04-01
EJB发布成功了吗?
回复
发动态
发帖子
中间件
创建于2007-08-27

1192

社区成员

企业软件 中间件技术
申请成为版主
社区公告
暂无公告