Java EE - 调用Remote Facade时获取InvocationTargetException?

时间:2012-04-06 04:46:11

标签: java-ee netbeans methods remote-access facade

我正在尝试制作企业应用程序但面临一个非常奇怪的错误。

每当我尝试从Main以外的任何类调用企业应用程序的Facade时,我都会遇到InvocationTargetException。

这是我的代码: -

public class TellerMachine {
    @EJB
    private static BillerFacadeRemote billerFacade;

    @EJB
    private static AccountFacadeRemote accountFacade;
    @EJB
    private static CustomerFacadeRemote customerFacade;
    @EJB
    private static BanktellerFacadeRemote banktellerFacade;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        TellerMachine tm = new TellerMachine();
        Scanner s = new Scanner(System.in);
        String sssa = billerFacade.hiHAHAHAHA();
        System.out.println(sssa);
        tm.printABC();
        TestClass t = new TestClass();
        t.abc();
    }

    public void printABC()
    {
        String sssa = billerFacade.hiHAHAHAHA();
        System.out.println(sssa);  
    }
}

测试类: -

public class TestClass 
{
@EJB
private static BillerFacadeRemote billerFacade;
public static void main(String[] args)
{

}
public void abc()
{
    try{
    String a = billerFacade.hiHAHAHAHA();
    System.out.println(a);}
    catch(Exception e)
    {
        System.out.println(e.getCause().toString());
    }
}

}

BillerFacade中的方法: -

@Override
public String hiHAHAHAHA() {
    return "abc";
}

堆栈追踪: -

Warning: /Users/varunbatra/Desktop/RealApp/SwinBankTellerMachine/dist/gfdeploy/SwinBankTellerMachine does not exist.
abc
abc
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.glassfish.appclient.client.acc.AppClientContainer.launch(AppClientContainer.java:438)
    at org.glassfish.appclient.client.AppClientFacade.main(AppClientFacade.java:165)
Caused by: java.lang.NullPointerException
    at swinbanktellermachine.TestClass.abc(TestClass.java:29)
    at swinbanktellermachine.TellerMachine.main(TellerMachine.java:52)
    ... 6 more
Java Result: 1

为什么会这样?有时甚至我从我的Main类调用远程方法它仍然给我这个例外。 Netbeans有什么问题?有时它有时可以工作。请帮助并清除我的困惑。

1 个答案:

答案 0 :(得分:0)

根据this stackoverflow discussion和引用的EJB规范,static注入仅允许在应用程序主类中。因此,注入适用于TellerMachine类,但不适用于TestClass TellerMachine方法中的被调用main实例。