Java 使用反射调用EJB3
在EJB3中,我们可以使用java反射调用它的方法吗?如果没有,我们可以使用Spring通过传递服务名称、方法名称和适当的参数来调用EJB3服务方法吗?是的,我们可以使用反射来调用EJB3方法。使用JNDI获取对该bean的引用,然后使用反射进行调用。这里有一个简单的例子(我使用的是OC4J)Java 使用反射调用EJB3,java,reflection,ejb-3.0,Java,Reflection,Ejb 3.0,在EJB3中,我们可以使用java反射调用它的方法吗?如果没有,我们可以使用Spring通过传递服务名称、方法名称和适当的参数来调用EJB3服务方法吗?是的,我们可以使用反射来调用EJB3方法。使用JNDI获取对该bean的引用,然后使用反射进行调用。这里有一个简单的例子(我使用的是OC4J) 这个代码对我有用。我使用了一个带有反射的ejb public class UTClasesReflects { public Object retornaInvoc(String clase, Strin
这个代码对我有用。我使用了一个带有反射的ejb
public class UTClasesReflects {
public Object retornaInvoc(String clase, String metodo,String contexto){
Class <?> remoto=null;
Proxy ed=null;
Object obj=null;
Method me=null;
UTCargaContextos utctx=null;
try {
utctx=UTCargaContextos.instancia();
obj=utctx.retornaContexto("wls_ejb_rs");//this method return jndi context, it's the same that ctx.lookup("jndiname");
ed=(Proxy) obj;
remoto=Class.forName(clase);
me=remoto.getMethod(metodo);
byte[] val=(byte[]) me.invoke(ed);
for (int i = 0; i < val.length; i++) {
System.out.println((char)val[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
public static void main(String[] args) {
UTClasesReflects a = new UTClasesReflects();
a.retornaInvoc("org.ve.bcv.extra.cta.producers.ConsumerRespuestaRemote","buscaRespuesta","wls_ejb_rs");
}
}
公共类utclases{
公共对象returnainvoc(字符串clase、字符串metodo、字符串contexto){
类remoto=null;
代理ed=null;
objectobj=null;
方法me=null;
UTCargaContextos utctx=null;
试一试{
utctx=UTCargaContextos.instancia();
obj=utctx.retronacontextro(“wls_ejb_rs”);//此方法返回jndi上下文,与ctx.lookup(“jndiname”)相同;
ed=(代理)obj;
remoto=Class.forName(clase);
me=remoto.getMethod(metodo);
字节[]val=(字节[])me.invoke(ed);
对于(int i=0;i
嗯,为什么不呢?从未检查过,但最有可能的是dep注入在后台使用反射。。。举个你想做什么的例子就好了。
public class UTClasesReflects {
public Object retornaInvoc(String clase, String metodo,String contexto){
Class <?> remoto=null;
Proxy ed=null;
Object obj=null;
Method me=null;
UTCargaContextos utctx=null;
try {
utctx=UTCargaContextos.instancia();
obj=utctx.retornaContexto("wls_ejb_rs");//this method return jndi context, it's the same that ctx.lookup("jndiname");
ed=(Proxy) obj;
remoto=Class.forName(clase);
me=remoto.getMethod(metodo);
byte[] val=(byte[]) me.invoke(ed);
for (int i = 0; i < val.length; i++) {
System.out.println((char)val[i]);
}
} catch (Exception e) {
e.printStackTrace();
}
return obj;
}
public static void main(String[] args) {
UTClasesReflects a = new UTClasesReflects();
a.retornaInvoc("org.ve.bcv.extra.cta.producers.ConsumerRespuestaRemote","buscaRespuesta","wls_ejb_rs");
}
}