本来是想做一个简单的EJB小例子的但报错了,调了半天也没找出错误:下面是代码:
(使用的是EJB3.0,)
package test;
import javax.ejb.Remote;
@Remote
public interface HelloWorld {
public String SayHello(String name);
}
package test.impl;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import test.HelloWorld;
@Stateless(mappedName = "myDate")
@Remote({HelloWorld.class})
public class HelloWorldBean implements HelloWorld {
@Override
public String SayHello(String name) {
// TODO Auto-generated method stub
return name+"说:终于成功了";
}
}
package test;
import java.io.IOException;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import test.HelloWorld;
public class EjbT extends HttpServlet {
@Override
protected void service(HttpServletRequest arg0, HttpServletResponse arg1)
throws ServletException, IOException {
String url = "t3://192.168.93.1:7001";
Properties p = new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL, url);
try {
Context context = new InitialContext(p);
Object a = context.lookup("ejb2ejb2_jarHelloWorldBean_Home");
System.out.println(a.getClass().toString()+"--------------------");
HelloWorld s=null;
s= (HelloWorld)a;
System.out.println(s.getClass());
arg0.setAttribute("message", s.SayHello("xianyu"));
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
arg0.getRequestDispatcher("/index.jsp").forward(arg0, arg1);
}
}
将ejb打包用weblogic发布,查看JNDI树
将HelloWorld接口打包在web程序里引用
报的错误如下:

我在想我是不是不该用EJB3.0啊,但网上大多说只有EJB3.0才好用点。
该贴由hui.chen转至本版2014-11-11 15:06:54
该贴由hui.chen转至本版2014-11-11 15:08:04