users@glassfish.java.net

Re: resource injection doesn't seem to be working...

From: Sahoo <Sahoo_at_Sun.COM>
Date: Wed, 18 Jul 2007 20:17:11 +0530

name in @Resource is not the JNDI name. You need to use mappedName to
specify the JNDI name as shown below:

@Resource(mappedName = "mail/test/myMailer")
  private Session session;


You can refer to [1] for some more explanation on this subject.

Thanks,
Sahoo

[1] https://glassfish.dev.java.net/servlets/ReadMsg?listName=dev&msgNo=4472
glassfish_at_javadesktop.org wrote:
> Hi,
>
> I'm trying to implement a small mail sender to test the resource injection feature. The problem is... it doesn't work :(
>
> I'm using the latest version (b55)
>
> The Mail session is defined in the server under the JNDI name "mail/test/myMailer"
>
> @Resource(name = "mail/test/myMailer")
> private Session session;
>
> In the doGet method, I have :
> // Create a MimeMessage
> out.write("-->" + session + "<--<br>");
> Message msg = new MimeMessage(session);
>
> I tried using the eclipse plugin, the automatic deployment directory and the "normal" deply button from the gui.
> The session object is always null.
>
> If I change the whole thing and use the "normal" way, defining the mail reference in the web.xml and sun-web.xml using
>
> InitialContext ic = new InitialContext();
> Session session2 = (Session)ic.lookup("java:comp/env/mail/test/myMailer");
>
> the whole thing is working correctly
>
> I tried to declare the mail session in the web.xml and then also in the sun-web.xml files (also I think it's not needed there) but the result was the same.
>
> anyone?
>
> greets
> jeremie
> [Message sent by forum member 'granat' (granat)]
>
> http://forums.java.net/jive/thread.jspa?messageID=227121
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>