• Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB3 Annotation  RSS feed

 
Cloey Tan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I was trying to annotate the ejb3 bean in a a separate class was failed to do so, and im wondering that method is relevant. For example, in my current class, i annotate
@EJB(beanName = "someDAOBean")
SomeDAO someDAO;

instead of doing this, i want to retrieve an instance of dao from a, say factory class..
SomeDAO someDAO = DaoFactory.getSomeDao();

and the annotation will be inside the DaoFactory. But i found that it doesnt work that way. Is there a reason for it?
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The @EJB annotation will work with any component registered with JavaEE container. BTW, why you need factory here? why not just use @EJB where you need it. The server will instantiate it for you, at the back most servers do pooling for EJB objects (stateless).

Otherwise, you can try to configure your factory in JNDI, that might possibly work.

Cheers.
 
Cloey Tan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the factory is for the sake of centralising the location of where all the class's beans are annotated, such that if one day the annotation is no longer in use, it can be switched easily inside the factory class instead of having to modify it inside every single class.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!