• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Class-level dependency

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regards!
I think it should not be work at all!
 
Tang Yue
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess the book means inside FooBar there is call to a method in Utility.java
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic