[jboss-user] [EJB 3.0] - Re: 2 Stateless session beans, same name+interface, differen

jaikiran do-not-reply at jboss.com
Thu Oct 16 09:26:17 EDT 2008


I do see the issue with the example that you have posted:

18:41:37,552 INFO  [STDOUT] invoking: greenwich.naming.WsTestBean
  | 18:41:37,552 INFO  [STDOUT] class of IBean used: greenwich.naming.BeanImpl2
  | 
I think the problem is because of the default jndi naming policy for EJBs. By default, the beans are bound to EARName/BeanName/local. Since in this case the BeanName (i.e. @Stateless(name="b1")) is the same for both the beans, the second bean (i.e BeanImpl2) is always injected by the EjbEncInjector.inject method . I have to look into the code to understand whether this is a bug. In the meantime, you have a workaround:

1) Add a @LocalBinding annotation to each of the beans to bind them to unique jndiNames as follows:

  | package greenwich.naming;
  | 
  | import javax.ejb.Stateless;
  | 
  | import org.jboss.annotation.ejb.LocalBinding;
  | 
  | @Stateless(name="b1")
  | @LocalBinding(jndiBinding = "Core-b1")
  | public class BeanImpl1 implements IBean {
  | 	public void invoke(){
  | 		System.out.println("class of IBean used: " + getClass().getName());
  | 	}
  | }
  |  

BeanImpl2:


  | package greenwich.naming;
  | 
  | import javax.ejb.Stateless;
  | 
  | import org.jboss.annotation.ejb.LocalBinding;
  | 
  | @Stateless(name="b1")
  | @LocalBinding(jndiBinding = "Project-b1")
  | public class BeanImpl2 implements IBean {
  | 	public void invoke(){
  | 		System.out.println("class of IBean used: " + getClass().getName());
  | 	}
  | }
  | 

You don't have to change anything else not even the injection part:

@Stateless(name="wsTest")
  | @WebService(name="naming")
  | public class WsTestBean implements IWsTestBean {
  | 	@EJB(beanName="b1")
  | 	IBean beanImpl;
  | 	
  | 	@WebMethod
  | 	public void testNaming(){
  | 		System.out.println("invoking: " + getClass().getName());
  | 		beanImpl.invoke();
  | 	}	
  | }
  | 

This should get it working properly, as i saw on my local setup (after the workaround):

  | 18:43:05,868 INFO  [STDOUT] invoking: greenwich.naming.WsTestBean
  | 18:43:05,868 INFO  [STDOUT] class of IBean used: greenwich.naming.BeanImpl1


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

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



More information about the jboss-user mailing list