• Post Reply Bookmark Topic Watch Topic
  • New Topic

Classes initiaed with new MyClass() - can i use @EJB in MyClass  RSS feed

 
Ally Cavs
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

Im working on a system that has no injections. All classes instantiated using new. We want to change dao layer from jdbc commit/rollback code and use JTA
So I want to inject MyDAOClass classes have





I can only inject MyDaoClass by looking up the context. I want to use @EJB for MyDaoClass injection. Parent class (business layer class) is instantiated with new. i dont want to rewrite everything and have every class injected.Can i use a annotation like @SessionScoped for business class to get JBOSS 6 to inject dao class?

 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Injection is supported only for "managed" instances. Using new() to instantiate doesn't allow injection to happen since the object is no longer managed by the container(s). So you will have to use the techniques specified by the Java EE spec to instantiate them (like using JNDI lookups or injection).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!