使用MyEclipse打包成EAR 部署至 JBoos 4.2.2package edu.zjut.ejb3;
/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 9:15:50 PM
* 浙江工业大学 E-mail:[email protected]
*/public interface HelloWorld {
public String SayHelloWorld();
public int getCount();
}package edu.zjut.ejb3;
import javax.ejb.Stateless;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:04 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Stateless
public class HelloWorldBean implements HelloWorldBeanLocal,
HelloWorldBeanRemote ,HelloWorld{
int count;
public String SayHelloWorld()
{
count++;
return "Hello World!";
} public int getCount()
{
return count;
}
}
package edu.zjut.ejb3;
import javax.ejb.Local;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:03 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Local
public interface HelloWorldBeanLocal {}
java Enterprise application 工程名是EJBProject
sessionbean 部署是成功的
+- EJBProject (class: org.jnp.interfaces.NamingContext)
| +- HelloWorldBean (class: org.jnp.interfaces.NamingContext)
| | +- local (proxy: $Proxy66 implements interface edu.zjut.ejb3.HelloWorldBeanLocal,interface org.jboss.ejb3.JBossProxy)
| | +- remote (proxy: $Proxy64 implements interface edu.zjut.ejb3.HelloWorldBeanRemote,interface org.jboss.ejb3.JBossProxy)index.JSP InitialContext ctx=new InitialContext();
Object local=ctx.lookup("EJBProject/HelloWorldBean/local");
out.println(local.getClass().getName());
out.println(local.toString());
正常输出 $Proxy66 HelloWorldBean InitialContext ctx=new InitialContext();
HelloWorld local=(HelloWorld)ctx.lookup("EJBProject/HelloWorldBean/local");
out.println(local.SayHelloWorld());
报错: java.lang.ClassCastException: $Proxy66 cannot be cast to edu.zjut.ejb3.HelloWorld
/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 9:15:50 PM
* 浙江工业大学 E-mail:[email protected]
*/public interface HelloWorld {
public String SayHelloWorld();
public int getCount();
}package edu.zjut.ejb3;
import javax.ejb.Stateless;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:04 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Stateless
public class HelloWorldBean implements HelloWorldBeanLocal,
HelloWorldBeanRemote ,HelloWorld{
int count;
public String SayHelloWorld()
{
count++;
return "Hello World!";
} public int getCount()
{
return count;
}
}
package edu.zjut.ejb3;
import javax.ejb.Local;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:03 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Local
public interface HelloWorldBeanLocal {}
java Enterprise application 工程名是EJBProject
sessionbean 部署是成功的
+- EJBProject (class: org.jnp.interfaces.NamingContext)
| +- HelloWorldBean (class: org.jnp.interfaces.NamingContext)
| | +- local (proxy: $Proxy66 implements interface edu.zjut.ejb3.HelloWorldBeanLocal,interface org.jboss.ejb3.JBossProxy)
| | +- remote (proxy: $Proxy64 implements interface edu.zjut.ejb3.HelloWorldBeanRemote,interface org.jboss.ejb3.JBossProxy)index.JSP InitialContext ctx=new InitialContext();
Object local=ctx.lookup("EJBProject/HelloWorldBean/local");
out.println(local.getClass().getName());
out.println(local.toString());
正常输出 $Proxy66 HelloWorldBean InitialContext ctx=new InitialContext();
HelloWorld local=(HelloWorld)ctx.lookup("EJBProject/HelloWorldBean/local");
out.println(local.SayHelloWorld());
报错: java.lang.ClassCastException: $Proxy66 cannot be cast to edu.zjut.ejb3.HelloWorld
@Local
public interface HelloWorldBeanLocal {而你的那个HelloWorld 接口,并没有被ejb代理所识别以上是我的猜测,楼主可以自己debug一下看一下$Proxy66是否只实现了一个接口
import javax.ejb.Stateless;
import javax.ejb.Local;
import javax.ejb.Remote;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:04 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Stateless
@Local (HelloWorld.class)
@Remote (HelloWorld.class)
public class HelloWorldBean implements HelloWorld{
int count;
public String SayHelloWorld()
{
count++;
return "Hello World!";
} public int getCount()
{
return count;
}
}index.JSP InitialContext ctx=new InitialContext();
HelloWorld local=(HelloWorld)ctx.lookup("EJBProject/HelloWorldBean/remote");
out.println(local.SayHelloWorld());
仍旧报java.lang.ClassCastException: $Proxy64 cannot be cast to edu.zjut.ejb3.HelloWorld而在Global JNDI Namespace 貌似也是正确的
+- EJBProject (class: org.jnp.interfaces.NamingContext)
| +- HelloWorldBean (class: org.jnp.interfaces.NamingContext)
| | +- local (proxy: $Proxy64 implements interface edu.zjut.ejb3.HelloWorld,interface org.jboss.ejb3.JBossProxy)
| | +- remote (proxy: $Proxy64 implements interface edu.zjut.ejb3.HelloWorld,interface org.jboss.ejb3.JBossProxy)
/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 9:15:50 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Local
public interface HelloWorld {
public String SayHelloWorld();
public int getCount();
}package edu.zjut.ejb3;
import javax.ejb.Stateless;/**
* @author 曹元彦
* @version V_1.0
* 创建时间:Feb 27, 2009 8:43:04 PM
* 浙江工业大学 E-mail:[email protected]
*/
@Stateless
public class HelloWorldBean implements HelloWorldBeanLocal,
HelloWorldBeanRemote ,HelloWorld{
int count;
public String SayHelloWorld()
{
count++;
return "Hello World!";
} public int getCount()
{
return count;
}
}客户端调用:
InitialContext ctx=new InitialContext();
HelloWorld local=(HelloWorldBean)ctx.lookup("EJBProject/HelloWorldBean/local");
out.println(local.SayHelloWorld());