This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 9915
    
158

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Class-level dependency
 
Similar Threads
java.lang.NoSuchMethodError
Dependancy Injection when 2 Beans implement the same interface
static inner class question.
association vs dependency
Using JNDI lookup to get access to the EJB