Since EJB 3.1, beans don't need to have a Local interface, and I usually don't use one:
@Stateless
public class MyService(){
public void buisnesssMethodA(){
...
}
public void buisnesssMethodB(){
...
}
}
and in my CDI bean I just do
@Inject
private MyService myService;
This is easy and simple and it works just fine.
Now I have recently discovered something.
Imagine I need an interface that represents a subset of my business method.
public interface MyInterface{
void businessMethodA();
}
Now if I make my Stateless bean implement this interface, JBoss fails to deploy and throws the error
WELD-001408 Unsatisfied dependencies for type [MyService] with qualifiers [@Default] at injection point [[field] @Inject
So I believe I'm observing the following rule:
If a stateless bean doesn't have an interface it can be injected using the class. If it implements an interface it must be injected using the interface.
Here are my questions:
- Is this rule correct?
- If so is it defined by the EBJ specs?
- What would be the reason for this restriction?
@LocalBean
annotation. That helped me in a similar situation. – Tom