users@glassfish.java.net

Mail Session is not injected to member field of my bean

From: <glassfish_at_javadesktop.org>
Date: Sun, 23 Mar 2008 13:47:46 PST

Hello!

I am using Sun Application Server 9.1. There I created a Mail Session, with the JNDI name "mail/mobileMailSession".

Then I have a session bean and within I want to use the mail session. Basic lookup works, like:

MailConfiguration mailConfiguration = (MailConfiguration)ic= new InitialContext().lookup("mail/mobileMailSession");
final java.util.Properties props = mailConfiguration.getMailProperties();
Session mailSession = javax.mail.Session.getInstance(props);
.... and so on, the mail finally is really sent, so all that works fine.

But rather than using the lookup I would like to inject the mail Session into a member filed of my bean. So I declared "Session mailSession" as member filed of my bean that way:

@Resource(name="mail/mobileMailSession") private javax.mail.Session mailSession;

The problem is, that no mail session is injected to the member field, so it is always null. Injection principally works with this bean, because I also inject the Entity Manager like this:

@PersistenceContext private EntityManager em;

So I don't understand why the mail session is not injected to the member field "mailSession".

Does anyone have any idea?

Best Regards, Georg
[Message sent by forum member 'horowitznotathome' (horowitznotathome)]

http://forums.java.net/jive/thread.jspa?messageID=265395