2

I'm still new with EJB and i have an injection issue.

I'am using the @Stateless annotation to create stateless beans. And I inject this beans by using the @EJB annotation. All works fine!

Then I did a new project setup. I have a common ejb project, which contains common logic. This common ejb project contains interfaces which are used to call specific logic of projects, which use this common ejb project. Still, everything works fine.

But: If a project, which uses the common ejb project, does not implement all interfaces, I receive an Exception on startup, that no implementation can be found for this interface and so nothing can be injected. Which is right, because there is no implementation.

But I want that in this case, the interface is just null. The reason is, that not all projects which use the common ejb project, want to use all of the common logic and so they don't have to implement all interfaces.

Of course i could do dummy interface-implementations but it would be nicer if there is something like in spring @Autowired(required=false)

Any idea to solve this issue?

Sabir Khan
  • 9,826
  • 7
  • 45
  • 98
user3227576
  • 554
  • 8
  • 22
  • There is a way to make an optional injection point with CDI which can be used for your EJBs. See [this question](http://stackoverflow.com/questions/19485878/can-inject-be-made-optional-in-jsr-330-like-autowirerequired-false) – Alexander Kravets May 12 '16 at 14:59
  • Hmm... sounds like a solution, but very compilcated for what i'd like to have. I think i will stay with the dummy interface-implementations... anyway, thank you for this link! – user3227576 May 14 '16 at 11:07

0 Answers0