I apologize if I should ask this in the
EJB or
JBOSS forums, but it seemed to be a general @Resource questions. I am not sure I understand how the @Resource annotation works. I am running on
java 1.7, JEE 6, and JBOSS AS 7.1.
The javax.annotation.Resources documentation indicates that the name parameter is the JNDI name of the resource. But lookups that fail using a JNDI name and thev@Resource annotation succeed when a JNDI context is obtained and used to look up the resource. For example in the code below I can successfully get a mail session if I comment out the @Resource annotation and uncomment the @PostConstruct annotation. In both cases the
string I use for JNDI name is "mail/yahoo"
If I run the code as shown attempting to use the @Resource annotation jboss reports the following error:
JBAS014775: New missing/unsatisfied dependencies:
service jboss.naming.context.java.comp.EJB05EAR.CHAP05EJB.StatusMailerBean.env.mail.yahoo (missing) dependents: [service jboss.deployment.subunit."EJB05EAR.ear"."CHAP05EJB.jar".component.StatusMailerBean.START]
The configuration entry in standalone.xml for the mail session is
<mail-session jndi-name="java:/mail/yahoo" from="jeff_gaer@yahoo.com">
<smtp-server ssl="true" outbound-socket-binding-ref="mail-smtp-yahoo">
<login name="jeff_gaer" password="xxxxxxxxxxx"/>
</mail-session>
I have a similar problem with otherJNDI lookups. I haven't used the @Resource annotation outside of the context of the examples in the "Beginning EJB3" (apress publications),