EJB world的新功能... EJB客户端中的空指针异常 [英] New to EJB world... Null pointer exception in EJB client

查看:130
本文介绍了EJB world的新功能... EJB客户端中的空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习EJB,我正在尝试执行EJB In Action书中给出的Helloworld示例。



我的应用服务器是JBoss,我创建了Jar文件bean类和接口在正确的目录(我可以看到JMX控制台中的EJB)。



现在我创建了一个简单的客户端使用EJB注释,但我正在空指针异常。



这是我的客户端代码。



客户端代码

  package com.client; 
import javax.ejb.EJB;
import com.EJB。*;

public class HelloWorldClient {
@EJB
private static HelloWorldInterface HelloBean;

public static void main(String [] args)
{
HelloBean.SayHelloWorldInEJB();
}
}

Bean类 p>

  package com.EJB; 

import javax.ejb.Stateless;

@Stateless
public class HelloWorldBean实现HelloWorldInterface {

public void SayHelloWorldInEJB(){
// TODO自动生成的方法存根
System.out.println(Hello world from the world of EJB);

}
}

界面

  package com.EJB; 
import javax.ejb.Local ;;

@Local
public interface HelloWorldInterface {
public void SayHelloWorldInEJB();
}

注意:我尝试使用将界面指定为Remote,但仍然没有工作。



到目前为止我已经做了一些步骤。
1)创建文件EJB文件
2)创建build.xml并部署EJB。



我没有任何配置文件? ?

解决方案


现在我使用EJB注释创建了一个简单的客户端,但是我收到了一个N​​ullPointerException。


您的客户端代码看起来像一个 应用程序客户端 ,这样的客户端应该在应用服务器上部署,然后执行一个应用程序客户端容器(ACC),以便可以进行注入。启动ACC需要应用程序服务器特定的命令。



以下wiki解释了在JBoss中使用ACC的方式(如何打包,部署和启动ACC):如何在JBoss-5中使用应用程序客户端



如果不想要使用应用程序客户端容器,而是通过java命令运行应用程序客户端类,注入将不可能,您必须执行JNDI查找。



在这两种情况下,您必须为您的bean提供和使用远程业务界面。



资源





相关问题




I am learning EJB and I am trying to execute the Helloworld example given in EJB In Action book.

My app server is JBoss, I created the Jar file for the bean class and interface in the right directory( I can see the EJB in JMX console).

Now I created a simple client using EJB annotations, but I am getting a NullPointerException.

Here is my client code.

Client code:

package com.client;
import javax.ejb.EJB;
import com.EJB.*;

public class HelloWorldClient {
 @EJB
 private static HelloWorldInterface HelloBean;

 public static void main(String[] args)
 {
  HelloBean.SayHelloWorldInEJB();
 }
}

Bean class

package com.EJB;

import javax.ejb.Stateless;

@Stateless
public class HelloWorldBean implements HelloWorldInterface {

 public void SayHelloWorldInEJB() {
  // TODO Auto-generated method stub
  System.out.println("Hello world from the world of EJB");

 }
}

Interface

package com.EJB;
import javax.ejb.Local;;

@Local
public interface HelloWorldInterface {
 public void SayHelloWorldInEJB();
}

Note: I tried using specifying the interface as Remote, it still didn't work.

Steps that I did so far to get to this point. 1) Created the file EJB files 2) Made the build.xml and deployed the EJB.

Am I missing any configuration files ???

解决方案

Now I created a simple client using EJB annotations, but I am getting a NullPointerException.

Your client code looks like an Application Client and such client is supposed to be deployed on the app server and then executed in an Application Client Container (ACC) so that injection can occur. Starting the ACC requires an application server specific command.

The following wiki explains the usage of the ACC in JBoss (how to package, deploy and launch an ACC): How to use an application client in JBoss-5.

If you don't want to use an Application Client Container and instead just run the application client class through a java command, injection won't be possible and you'll have to perform a JNDI lookup.

And in both cases, you'll have to provide and use a remote business interface for your bean.

Resources

Related questions

这篇关于EJB world的新功能... EJB客户端中的空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆