Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:But the 'name' attribute also does injection of resources bound in the EJB's environment, right? Like if you specify in ejb-jar.xml an env-entry "myString" for some EJB, the following:
@Resource(name="myString")
String myString;
will inject the resource
and for, let's say a datasource, which is specified as "java:comp/env/jdbc/Muppets" in the JNDI context, the 'name' property is not binding it when it injects this value using:
@Resource(name="jdbc/Muppets")
DataSource ds;
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Dieter Quickfend wrote:So, if I'm understanding you correctly, specifying "@Resource(name='thisResource') String myString;" behaves exactly the same as "@Resource String myString;" except that the former will also bind the value injected into this component (without knowing where it got it from) as 'thisResource' in the ENC (assuming 'thisResource' doesn't exist)? What happens if 'thisResource' already exists?
What happens if 'thisResource' already exists?
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
That clears it up for me. So @Resource(name="") is actually a code-level declaration of an env-entry rather than a JNDI lookup of an env-entry.
And yes, I've been using your notes intensively, after reading the specification, to prepare for the EJB certification (which will be in a few weeks). Thanks a lot, both for this explanation and for your awesome notes! They've been a big help!
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Frits Walraven wrote:
(I still find the description in the EJB specs is lacking some important aspects)
Jaikiran Pai wrote:
From what I remember the explanation of @Resource is probably done more in the Java EE spec rather than in EJB spec.
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
Oracle Certified Professional: Java SE 6 Programmer && Oracle Certified Expert: (JEE 6 Web Component Developer && JEE 6 EJB Developer)
I was her plaything! And so was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|