Reputation: 22027
I defined an interface.
@Local
public interface MessageService {
}
And an implementation.
@Stateless
public class MessageServiceSome implements MessageService {
}
When I tried to inject it into my resource class, I got null
.
//@Path("/messages") // I'M NOT GOING TO MAKE THIS STATELESS!!!
public class MessagesResource {
// none of follwoing options works
// leaves the field null
@Inject
//@EJB
//@EJB(beanName = "MessageServiceSome")
private MessageService messageService;
}
How can I solve this?
UPDATE
I think I have to admit that my question is not good enough.
The MessagesResource
class was actually a sub resource. I didn't know the difference.
There are two very good threads for this issue.
One is using ResourceContext and the other is using Inject.
Both threads are saying they work but I only succeeded with @Inject
.
Upvotes: 1
Views: 981
Reputation: 9857
With little information provided, you have probably two quick options you can try:
leave @Inject only, if your project/container is CDI enabled
@Inject private MessageService messageService;
leave @EJB only, do you really need the beanName ?
@EJB private MessageService messageService;
on of the two should solve the issue.
[UPDATE] Otherwise have a look at the app server start up log, and see if the bean has been deployed.
Upvotes: 2