aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Class-level dependency Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Class-level dependency" Watch "Class-level dependency" New topic
Author

Class-level dependency

Tang Yue
Ranch Hand

Joined: Nov 11, 2008
Posts: 40
In the SCBCD5 Study Guide, there is an example of class-level dependency:

FooBean.java
@EJB(name="ejb/bar", beanInterface=Bar.class)

public class FooBean implements Foo {
...
}

Utility.java
Bar bar = (Bar) context.lookup("java:comp/env/ejb/bar");

I don't understand this example. If Utility.java needs a Bar, shouldn't it use @EJB in Utility.java? Why @EJB is used in FooBean.java? I don't see how these 2 java files are related at all.


Houston Rockets go go go!
Fu Dong Jia
Ranch Hand

Joined: May 23, 2007
Posts: 131
Regards!
I think it should not be work at all!


who dare win!<br />SCJP5(94%)|SCWCD5(86%)|SCBCD(100%)|SCEA in progress
Tang Yue
Ranch Hand

Joined: Nov 11, 2008
Posts: 40
I guess the book means inside FooBar there is call to a method in Utility.java
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10213
    
166

Originally posted by Tang Yue:
In the SCBCD5 Study Guide, there is an example of class-level dependency:

FooBean.java
@EJB(name="ejb/bar", beanInterface=Bar.class)

public class FooBean implements Foo {
...
}

Utility.java
Bar bar = (Bar) context.lookup("java:comp/env/ejb/bar");

I don't understand this example. If Utility.java needs a Bar, shouldn't it use @EJB in Utility.java? Why @EJB is used in FooBean.java? I don't see how these 2 java files are related at all.


Without looking at the code in the FooBean, i can only guess that the Utility.java class is being used in this bean. Going by the name of the "Utility" class, i guess its an unmanaged object - which means that you cannot use injection in this class. Effectively, you cannot use @EJB injection to get hold of the "Bar" bean. And that the reason why the Bar bean is being injected in the ENC of the FooBean so that the utility class can look it up from the ENC (java:comp/env namespace) of the FooBean.


[My Blog] [JavaRanch Journal]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Class-level dependency