我试图将一个EJB无状态bean注入到一个servlet中,但是servlet会抛出一个NullPointerExcetion.我正在使用JBOSS来部署EJB和servlet.
我对Java世界比较陌生,所以我发布了我遵循的步骤.
接口
package MavenEJB.Bidding`
import javax.ejb.Local;
@Local
public interface PlaceBid {
public String AddBid();
}
Run Code Online (Sandbox Code Playgroud)
豆
package MavenEJB.Bidding;
import javax.ejb.Stateless;
@Stateless(name="PlaceBid")
public class PlaceBidBean implements PlaceBid {
public PlaceBidBean(){}
/**
* Include logic to add the bid
*/
public String AddBid(){
return "Placed bid using EJB";
}
}
Run Code Online (Sandbox Code Playgroud)
我使用maven创建了一个bean的jar文件,然后将jar文件复制到JBOSS的"deploy"目录中.我能够看到在JMX控制台中部署的bean.
JMX控制台中的全局JNDI命名空间
+- PlaceBid (class: org.jnp.interfaces.NamingContext)
| +- local (proxy: $Proxy63 implements interface MavenEJB.Bidding.PlaceBid,interface org.jboss.ejb3.JBossProxy)
Run Code Online (Sandbox Code Playgroud)
我的servlet代码
public class PlaceBidServlet extends HttpServlet {
@EJB
private PlaceBid placeBid;
protected void doGet(HttpServletRequest request, HttpServletResponse …Run Code Online (Sandbox Code Playgroud) 我正在学习EJB,我正在尝试执行EJB In Action书中给出的Helloworld示例.
我的app服务器是JBoss,我在正确的目录中为bean类和接口创建了Jar文件(我可以在JMX控制台中看到EJB).
现在我使用EJB注释创建了一个简单的客户端,但是我得到了一个NullPointerException.
这是我的客户端代码.
客户代码:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
Bean类
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");
}
}
Run Code Online (Sandbox Code Playgroud)
接口
package com.EJB;
import javax.ejb.Local;;
@Local
public interface HelloWorldInterface {
public void SayHelloWorldInEJB();
}
Run Code Online (Sandbox Code Playgroud)
注意:我尝试将接口指定为Remote,但仍然无法正常工作.
到目前为止我做的步骤是为了达到这一点.1)创建文件EJB文件2)制作build.xml并部署EJB.
我错过了任何配置文件???
我正在使用Ganymed API来进入Unix服务器.我能够在服务器中创建文件,但文件的内容始终为空.
Ganymed API位置:http://www.ganymed.ethz.ch/ssh2/
码:
function (ByteArrayOutputStream reportBytes){
// reportBytes is a valid ByteArrayOutputStream
// if I write it to a file in to a local directory using reportBytes.writeTo(fout);
// I can see the contents */
byte byteArray[]=reportBytes.toByteArray();
SFTPv3FileHandle SFTPFILEHandle=sftpClient.createFileTruncate("test.txt");
//The file is created successfully and it is listed in unix
// The permissions of the file -rw-r--r-- 1 test.txt
sftpClient.write(SFTPFILEHandle, 0, byteArray, 0,byteArray.length );
//The above line doesnt seem to work, the file is always empty
} …Run Code Online (Sandbox Code Playgroud)