aspose file tools*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes DI in helper classes 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 "DI in helper classes" Watch "DI in helper classes" New topic
Author

DI in helper classes

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Guys,

I have a small doubt from the EJB 3.0 in Action book,

Here it is...To look up a resource from the helper class, you have to reference the reouurce in the EJB class as follows,

@Resource(name="jdbc/actionBazaarDB", mappedName="jdbc/actionBazaarDS", type=javax.sql.Datasource.class)

@Stateless
public class PlaceBidBean implements PlaceBid

You can look up the resource either from the EJB or the helper class as follows:

Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/ActionBazaarDB);


I understand that we cannot use DI in un-managed classes, but from the above code, how will my @Resource Annotation know which helper class to look for doing the DI?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi Jothi


in your example you deal with a managed class because you use the @Stateless annotation.
The container will use the mappedName together with the name to inject the needed instance.


Regards,
M


SCJP, SCJD, SCWCD, OCPJBCD
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9629
    
    2

Originally posted by Mihai Radulescu:
Hi Jothi


in your example you deal with a managed class because you use the @Stateless annotation.
The container will use the mappedName together with the name to inject the needed instance.


Regards,
M


Where will the container look for the mappedName?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DI in helper classes