处理远程/本地会话Bean [英] Acessing Remote/Local Session Beans

查看:83
本文介绍了处理远程/本地会话Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到会话bean。我尝试了许多不同的方式,我发现与Google,但我总是得到相同的错误,因为我的JNDI查找总是返回NULL。

I'm trying to connect to a session bean. I tried many different ways that I found with Google, but I always get the same error because my JNDI lookup always returns NULL.

这是错误:

java.lang.NullPointerException
at org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:333)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:399)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:317)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:204)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:311)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)






所以,我可能是缺少一些配置,但是这个东西的新手有一点帮助?


So, I'm probably missing some configuration, but I'm newbie in this stuff. A little help?

这是我的实体Bean:

Here's my Entity Bean:

 package beans;
 import java.util.HashSet;
 import java.util.Set;
 import javax.persistence.*;
 import org.hibernate.annotations.GenericGenerator;

@Entity
public class Album {

@Id
@Column(name="idalbum")
@GeneratedValue(generator="album_idalbum_seq")
@GenericGenerator(name="album_idalbum_seq", strategy = "increment")
private int id;

@Column(name="nomealbum")
private String nome;

@ManyToMany
  @JoinTable(name = "albumfaixas",
          joinColumns = { 
          @JoinColumn(name = "idalbum") 
          },
          inverseJoinColumns = {
          @JoinColumn(name="idfaixas")
          }
  )
private Set<Faixas> faixas = new HashSet<Faixas>();

public Album() {}
//gets and sets
}

我的会话Bean:

 package DAO;
 import org.hibernate.*;
 import sFactory.*;
 import java.util.List;
 import javax.ejb.Stateless;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
 import beans.*;


 @Stateless 

 public class AlbumDAO  implements AlbumRemote { 

 @PersistenceContext 
  private EntityManager entityManager;

public List<Album> listaAlbuns() { ... code ... }
public void createAlbum(Album f) { ... code ... }
public void updateAlbum(Album f) { ... code ... }
public void deleteAlbum(Album f) { ... code ... }
 }

我的远程接口:

 package DAO;
 import javax.ejb.Remote;
 import java.util.List;
 import beans.Album;

 @Remote 

 public interface AlbumRemote {

public List<Album> listaAlbuns();
public void createAlbum(Album f);
public void updateAlbum(Album f);       
public void deleteAlbum(Album f);
 }

我的本​​地界面:

 package DAO;
 import javax.ejb.Local;
 import java.util.List;
 import beans.Album;

 @Local

 public interface AlbumLocal {

public List<Album> listaAlbuns();
public void createAlbum(Album f);
public void updateAlbum(Album f);   
public void deleteAlbum(Album f);
 }

web.xml中的引用:

The reference in web.xml:

   <ejb-ref>
     <ejb-ref-name>ejb/AlbumRemote</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
     <home>DAO.AlbumLocal</home>
     <remote>DAO.AlbumRemote</remote>
   </ejb-ref>

我的JSP客户端代码:

My JSP Client code:

Context initCtx = new InitialContext();

Context ctx = (Context) initCtx.lookup("java:comp/env"); 

Object x = ctx.lookup("ejb/AlbumRemote");

AlbumRemote fr = (AlbumRemote)PortableRemoteObject.narrow(x, AlbumRemote.class);

fr.createAlbum(fx1);    

我正在使用myeclipse进行开发,Tomcat用于服务器

I'm using myeclipse for developing and Tomcat for server

推荐答案

你真的很亲密。删除 openejb.war文件,此代码应该可以工作。

You're really close. Drop in the openejb.war file and this code should work.

Tomcat本身不支持EJB,但是可以通过OpenEJB轻松实现。实际上,我们现在打电话给这个组合 Apache TomEE ,并且正在进行Java EE 6 Web Profile认证。所以它将在Glassfish,JBoss,Geronimo等的行列。

Tomcat doesn't natively support EJBs, but it can easily be made to do so with OpenEJB. In fact we are now calling this combo Apache TomEE and are in the process of Java EE 6 Web Profile certifying it. So it will be in the ranks of Glassfish, JBoss, Geronimo, etc.

如果你还没有,请确保有一个 WEB-INF / classes / META-INF / persistence.xml 文件在您的应用程序中定义您的持久性单位。

In case you don't already have one, make sure there is a WEB-INF/classes/META-INF/persistence.xml file in your app that defines your persistence unit.

这篇关于处理远程/本地会话Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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