| Author |
DI in helper classes
|
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
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, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
|
 |
Mihai Radulescu
Ranch Hand
Joined: Sep 18, 2003
Posts: 912
|
|
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
|
 |
Joe Harry
Ranch Hand
Joined: Sep 26, 2006
Posts: 8795
|
|
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?
|
 |
 |
|
|
subject: DI in helper classes
|
|
|