看看你的lookup()方法中jndi-name与JBoss.xml中的jndi-name是否一致。
解决方案 »
- hibernate Transformers的问题
- struts2配置文件的result,跳转到其它命名空间里的action,怎么写
- 实现网络化,多线程的记事本系统
- 跟大家分享一个大数据实战教程资料
- 当客户端死机后,如何通过管理员remove这个客户端占用的stateful session bean?
- 谁能说一下ejb的安全?
- 有人说Struts效率不高,大家讨论一下
- javabean是不是类似于Vc中的dll啊?初学java
- 谁能告诉我数据库连接池!急急急!!!!!!!!!!!!!!
- 读j2ee tutorial时遇到的问题
- 给个XML的例子,急,在线D呀
- JB7開發CMP的連接資料庫的問題
import javax.naming.*;
import com.web_tomorrow.interest.*;
import java.util.Hashtable;
import java.util.*;
import javax.rmi.PortableRemoteObject;
import com.web_tomorrow.interest.*; /**
This simple application tests the `Interest' Enterprise JavaBean which is
implemented in the package `com.web_tomorrow.interest'. For this to work, the
Bean must be deployed on an EJB server.
<p>
<b>IMPORTANT</b> If you want to test this in a real client-server
configuration, this class goes on the client; the URL of the naming provider
specifed in the class must be changed from `localhost:1099' to the URL of the
naming service on the server
*/class InterestClient
{
/**
This method does all the work. It creates an instance of the Interest EJB on
the EJB server, and calls its `calculateCompoundInterest()' method, then prints
the result of the calculation.
*/
public static void main(String[] args)
{
// Set up the naming provider; this may not always be necessary, depending
// on how your Java system is configured.
/*
System.setProperty("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url",
"localhost:1099");
*/
//Properties p = new Properties();
//p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
//p.put("javax.naming.provider.url","iipo://localhost:1099");
java.util.Hashtable JNDIParm = new java.util.Hashtable();
JNDIParm.put(Context.PROVIDER_URL, "localhost");
JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
// Enclosing the whole process in a single `try' block is not an ideal way
// to do exception handling, but I don't want to clutter the program up
// with catch blocks
try
{
// Get a naming context
InitialContext jndiContext = new InitialContext(JNDIParm);
System.out.println("Got context"); // Get a reference to the Interest Bean
Object ref = jndiContext.lookup("interest/Interest");
System.out.println("Got reference"); // Get a reference from this to the Bean's Home interface
InterestHome home = (InterestHome)
PortableRemoteObject.narrow (ref, InterestHome.class); // Create an Interest object from the Home interface
Interest interest = home.create();
// call the calculateCompoundInterest() method to do the calculation
System.out.println
("Interest on 1000 units, at 10% per period, compounded over 2 periods is:");
System.out.println (interest.calculateCompoundInterest (1000, 0.10, 2));
}
catch(Exception e)
{
System.out.println(e.toString());
}
}
}
private javax.naming.Context getJBossInitialContext() throws NamingException {
java.util.Hashtable JNDIParm = new java.util.Hashtable();
JNDIParm.put(Context.PROVIDER_URL, "localhost");
JNDIParm.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); return new InitialContext(JNDIParm);
}