• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
reply
    Bookmark Topic Watch Topic
  • New Topic