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:
From my limited knowledge of Java EE and CDI:
Hope this answers your question 3, and partly confirms, partly invalidates your rule from questoin 1. I cannot be bothered now to answer question 2 though...
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.