Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

few queries regarding injection and InitialContext?

 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can resource injection be ONLY performed from bean classes and application client class OR it can also be performed from simple POJO class that is in my EAR or ejb-jar.jar project ?

also if I have a POJO class and I have defined a jms resource with JNDI name as jms/MyQueueFactory in glassfish service I know I can access it using no-arg InitialContext constructor but my question is how it is possible in simple POJO class. I haven't read about this in the spec also. don't we need to pass environment properties to the InitialContext constructor ? is it a vendor provided feature ?

thanks and regards
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi gurpreet,

1) POJO doesn't have access to ENC by default (it needs some properties to get that access), and hence, though the annotations are allowed in POJO, those won't inject an actual EJB in it (e.g. who will inject EJB in case of POJO? how would runtime get to know where to look for that particular EJB? etc.)

2) As mentioned above, you can access JMS queue after getting a proper context. In POJO, to get a proper context, some properties are necessary (e.g. context factory, security principle - if configured etc.). In a POJO, if no-arg InitialContext constructor is called, then a NoInitialContextException will be thrown.

I'm not expert in this area, so comments/corrections welcome.

Thanks.
 
gurpeet singh
Ranch Hand
Posts: 924
1
Fedora Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
waiting for other ranchers to comment on this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic