如何在 EJB 3 实体中使用 Java Reflection API?
我使用 eclipse 3.5、JBoss 4.2、EJB3 执行以下步骤,但遇到类未找到异常
1.将此代码编译到 foo.jar 文件
package mypackage.foo;
import myejbpackage.ejb.fooInterface;
class foo implements fooInterface{
@override
void helloWorld(){System.out.print("HelloWorld");}
}
请注意,fooInterface 接口是在使用的 EJB 内部编写的
2.使用反射,我举一个实例从此类,也具有相同的 ejb
package myejbpackage.ejb;
class fooCaller{
void call(){
Class foo= Class.forName("mypackage.foo.foo");
fooInterface iDataBackupWriter =(fooInterface) foo.newInstance(); fooInterface.helloWorld(); } 3.
然后在无状态 ejb3 中调用它
package myejbpackage.ejb;
test(){
System.Out.Write("before calling");
new fooCaller().call();
}
4.然后部署到 Jboss 4.2 并将 foo.jar 放入 default/lib
5.然后调用 ejb 3 方法。使用简单客户端
打印:
"before calling"
中出现以下异常
javax.ejb.EJBException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: myejbpackage/ejb/fooInterface; nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundError: myejbpackage/ejb/fooInterface
java.lang.RuntimeException: java.lang.NoClassDefFoundError:myejbpackage/ejb/fooInterface
并且在 eclipse控制台 建议 ? 1.这是JBOOS的异常吗?为什么? 1.我应该把 foo.jar 放在哪里才能与 ejb3 jar 一起看到?
提前致谢
I do the following steps with eclipse 3.5 ,JBoss 4.2 ,EJB3 but I face class not found exception
1.compiling this code to foo.jar file
package mypackage.foo;
import myejbpackage.ejb.fooInterface;
class foo implements fooInterface{
@override
void helloWorld(){System.out.print("HelloWorld");}
}
Note that fooInterface interface in is written inside the used EJB
2.using reflection , I take an instance from this class, also with the same ejb
package myejbpackage.ejb;
class fooCaller{
void call(){
Class foo= Class.forName("mypackage.foo.foo");
fooInterface iDataBackupWriter =(fooInterface) foo.newInstance();
fooInterface.helloWorld();
}
}
3.then calling it within stateless ejb3
package myejbpackage.ejb;
test(){
System.Out.Write("before calling");
new fooCaller().call();
}
4.then deploying to Jboss 4.2 and and puting foo.jar in default/lib
5.then calling the ejb 3 method.using simple client
it print :
"before calling"
and the following exception occurs in eclipse console
javax.ejb.EJBException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: myejbpackage/ejb/fooInterface; nested exception is: java.lang.RuntimeException: java.lang.NoClassDefFoundError: myejbpackage/ejb/fooInterface
java.lang.RuntimeException: java.lang.NoClassDefFoundError:myejbpackage/ejb/fooInterface
Any suggestion ?
1.Is this exception from JBOOS, why ?
1.Where I should put the foo.jar to bee seen with the ejb3 jar ?
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
存在产生此问题的循环依赖
there was a circular dependency which generate this problem