[jboss-user] [Beginners Corner] - trouble obtaining EJB reference in portlet

bernieb do-not-reply at jboss.com
Sun Aug 13 23:31:23 EDT 2006


I'm having trouble obtaining a reference to an EJB entity bean in a portlet.

The entity bean has successfully deployed and I've confirmed the JNDI name in the jmx-console (PersonBean).

I had first tried to obtain the reference through the EJB annotation, injecting it into the portlet as such:

  | public class ModifyPerson extends GenericPortlet {
  | @EJB(name="PersonBean")
  | private PersonLocal bean;
  | .
  | .
  | .
  | }
  | 
(PersonLocal is the local interface)

However, this did not appear to work as I got a NullPointerException when I tried to call any of its methods.

When that faied, I tried to do a JNDI lookup in the init() method:
	
  | public void inti() throws PortletException{
  | 	try{
  | 		InitialContext ctx = new InitialContext();
  | 		bean = (PersonLocal) ctx.lookup("java:/env/comp/PersonBean");
  | 	}catch(NamingException ex){
  | 		throw new PortletException(ex.getMessage());
  | 	}
  | }
  | 

The portlet instance did not appear to have thrown any exceptions when initializing, which I had thought was promising, but when I try to call any of the bean's methods, I still get the NullPointerException.

I am assuming this NullPointerException is the result of bean remaining as a null value as an actual reference to the bean is not obtained.

Any help in this matter will be greatly appreciated.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3964871#3964871

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3964871



More information about the jboss-user mailing list