• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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).
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic