As per the Netbeans Tutorial on EJB Client applications, I cannot seem to invoke the method:
compile error:
-do-compile:
[mkdir] Created dir: /home/thufir/NetBeansProjects/EntAppClient/build/empty
[mkdir] Created dir: /home/thufir/NetBeansProjects/EntAppClient/build/generated-sources/ap-source-output
[javac] Compiling 1 source file to /home/thufir/NetBeansProjects/EntAppClient/build/jar
[javac] /home/thufir/NetBeansProjects/EntAppClient/src/java/entappclient/Main.java:16: error: cannot find symbol
[javac] System.err.println("result = " + mySession.getResult());
[javac] ^
[javac] symbol: method getResult()
[javac] location: variable mySession of type MySessionRemote
[javac] 1 error
BUILD FAILED
client:
package entappclient;
import ejb.MySessionRemote;
import javax.ejb.EJB;
public class Main {
@EJB
private static MySessionRemote mySession;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.err.println("result = " + mySession.getResult());
}
}
ejb:
package ejb;
import javax.ejb.Stateless;
@Stateless
public class MySession implements MySessionRemote {
public String getResult() {
return "This is My Session Bean";
}
}
remote interface:
package ejb;
import javax.ejb.Remote;
@Remote
public interface MySessionRemote {
}
now, if the interface is modified:
package ejb;
import javax.ejb.Remote;
@Remote
public interface MySessionRemote {
public String getResult();
}
the bean can now @Override
the method:
package ejb;
import javax.ejb.Stateless;
@Stateless
public class MySession implements MySessionRemote {
@Override
public String getResult() {
return "This is My Session Bean";
}
}
however, there's a NPE:
-run:
[java] java.lang.reflect.InvocationTargetException
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[java] at java.lang.reflect.Method.invoke(Method.java:606)
[java] at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:446)
[java] at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:166)
[java] Caused by: java.lang.NullPointerException
[java] at entappclient.Main.main(Main.java:16)
[java] ... 6 more
[java] Java Result: 1
run:
BUILD SUCCESSFUL
Total time: 18 seconds
thufir@dur:~/NetBeansProjects/EntAppClient$
How can I invoke the method correctly? The EJB isn't instantiated?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…