Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about class-level DI

 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mock question:

A developer writes a stateful session bean called FooBean.
Which code can be inserted before Line 11 of the FooBean class to define a TYPE-level
environment dependency on a JMS Topic?
11. public class FooBean {
12.
13. public void foo() {}
14.
15. }
A. @Resource(type=Topic.class)
B. @Resource(name="topicRef")
private static Topic topic;
C. @Resource private Topic topic;
D. @Resource(name="topicRef" ,type=Topic.class)

given anwser is D,B is wrong apparently,C is not TYPE-LEVEL,but why A is wrong?,and one more doubt,when we using TYPE-LEVEL DI,like this(put @Resource before line 11),which field of this class accept the injection?
 
uday ogra
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if A is right than how are you going to lookup for this resource in the code using JNDI ...you need some name by which you can lookup the injected resource
[ March 25, 2008: Message edited by: uday ogra ]
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,Uday,I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic