//Remote接口
public interface HelloWord extends EJBObject {
public String hello() throws RemoteException;
}
//Home接口
public interface HelloWordHome extends EJBHome {
public HelloWord creat() throws RemoteException,CreateException;
}
//SessionBean
public class HelloWordBean implements SessionBean {
private SessionContext context;
private String words; public HelloWordBean() {} public void ejbActivate() throws EJBException, RemoteException {} public void ejbPassivate() throws EJBException, RemoteException {} public void ejbRemove() throws EJBException, RemoteException {} public void setSessionContext(SessionContext newContext)
throws EJBException {
context = newContext;
}
public void ejbCreate() throws CreateException{
words = "成功了";
}
public String hello(){
System.out.println("第一个EJB例子" + words);
return words;
}
public void replaceWithRealBusinessMethod() throws EJBException {}}
然后部署到glassfish中,究竟是打成jar包还是war包
接着又写了个测试程度调用
public class HelloClient { public static void main(String[] args) throws NamingException, RemoteException, CreateException {
try{
//初始化Context实例
InitialContext ic = new InitialContext();
//执行JNDI查找
HelloWordHome home =(HelloWordHome)ic.lookup("com.Kingdosoft.zjj.HelloWordHome");
System.out.println("完成JNDI查找");
//调用Home接口的creat方法,返回Remote接口实例
HelloWord hw = home.creat();
System.out.println("完成HelloWord的Remote接口的创建");
//调用业务逻辑方法
System.out.println(hw.hello());
}catch(Exception e){
e.printStackTrace();
}
}
}
再然后就抛异常了
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.Kingdosoft.zjj.HelloClient.main(HelloClient.java:27)
就是执行jndi查找有问题
有高手能解决下么。。小弟感激不尽
public interface HelloWord extends EJBObject {
public String hello() throws RemoteException;
}
//Home接口
public interface HelloWordHome extends EJBHome {
public HelloWord creat() throws RemoteException,CreateException;
}
//SessionBean
public class HelloWordBean implements SessionBean {
private SessionContext context;
private String words; public HelloWordBean() {} public void ejbActivate() throws EJBException, RemoteException {} public void ejbPassivate() throws EJBException, RemoteException {} public void ejbRemove() throws EJBException, RemoteException {} public void setSessionContext(SessionContext newContext)
throws EJBException {
context = newContext;
}
public void ejbCreate() throws CreateException{
words = "成功了";
}
public String hello(){
System.out.println("第一个EJB例子" + words);
return words;
}
public void replaceWithRealBusinessMethod() throws EJBException {}}
然后部署到glassfish中,究竟是打成jar包还是war包
接着又写了个测试程度调用
public class HelloClient { public static void main(String[] args) throws NamingException, RemoteException, CreateException {
try{
//初始化Context实例
InitialContext ic = new InitialContext();
//执行JNDI查找
HelloWordHome home =(HelloWordHome)ic.lookup("com.Kingdosoft.zjj.HelloWordHome");
System.out.println("完成JNDI查找");
//调用Home接口的creat方法,返回Remote接口实例
HelloWord hw = home.creat();
System.out.println("完成HelloWord的Remote接口的创建");
//调用业务逻辑方法
System.out.println(hw.hello());
}catch(Exception e){
e.printStackTrace();
}
}
}
再然后就抛异常了
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:247)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:284)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at com.Kingdosoft.zjj.HelloClient.main(HelloClient.java:27)
就是执行jndi查找有问题
有高手能解决下么。。小弟感激不尽
解决方案 »
- Struts2.0+Springframework2.5+ibatis2.3架包
- 能帮我看看这是什么问题吗?先谢谢了!:)
- 哪里有JMS的视频教程的
- 新手问题,急,运行时不出现羡慕里的页面??
- 求struts2.0的相关资料
- 一个在eclipse中才出现的异常
- 新手问tomcat下Servlet问题
- 关于struts中自带的标签的问题
- 高手请教 :) (探讨类)散分
- lucene4.7删除索引失败
- java.io.StreamCorruptedException: invalid type code: 31,eclipse下用ant发布时发生如下错误,网上查了一下不知道是不是jdk1.6的bug
- 请问怎样能学精通javascript
try {
String url = "t3://localhost:7001";
String user = "weblogic";//weblogic 管理用户名
String password = "weblogic";//weblogic 管理密码
Properties props = new Properties();
props.put(Context.PROVIDER_URL,url);
props.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
props.put(Context.SECURITY_PRINCIPAL,user);
props.put(Context.SECURITY_CREDENTIALS,password);
ctx = new InitialContext(props);
ctx.lookup(.......); .......
} catch (Exception ex) {
ex.printStackTrace();
}