Reputation: 290
I'm a newbie to ejb .I want to know is can two session beans implement the same remote(local) interface, if not why?
The code example is welcome.
Thanks for any help!
Upvotes: 0
Views: 1409
Reputation: 740
Yes you can.
You can implement any interface(local and remote) by any number of beans, but then you need to specify which particular beans you are injecting.
For simple example you can use beanName
attribute:
@Remote
public interface Worker {}
//
@Stateless(name = "firstBean")
public class Bean1 implements Worker {}
//
@Stateless(name = "secondBean")
public class Bean2 implements Worker {}
//
@Stateless
public class LogicBean {
@EJB(beanName = "firstBean")
private Worker worker1;
@EJB(beanName = "secondBean")
private Worker worker2;
}
Also you can play around with jndi names
through mappedName
attribute.
See also:
https://developer.jboss.org/thread/230291?tstart=0
Upvotes: 1
Reputation: 13857
Yes, they can.
Example:
public interface NodeService {
public void start();
}
First implementation:
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Remote(NodeService.class)
public class NodeService1 implements NodeService {
@Override
public void start() {
}
}
Second implemenation:
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;
@Stateless
@Remote(NodeService.class)
public class NodeService2 implements NodeService {
@Override
public void start() {
}
}
See also:
Upvotes: 2