关于jbuilder5和weblogic6.1联合开发ejb的问题。
大家好,我在用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)
现在我已经试了很多次了,还是不能成功,谢谢大家指教。