(UPDATED)
I have deployed a web application on jboss-as-7.1.1.Final as standalone, and I have one startup class to initialize as below which works fine:
@Startup
@Singleton
public class StartupBean {
@PostConstruct
void init() {
EmailSenderService emailSenderService = new EmailSenderService();
emailSenderService.testMail();
}
}
the problem is in the other class defined as following:
@Stateless
public class EmailSenderService {
@Resource(mappedName="java:jboss/mail/Default")
private Session mailSession;
@PostConstruct
public void testMail(){
if(mailSession == null){
System.out.println("NULL");
}
}
}
when starting the application server, the method is called by the startup class, however the mailSession property is not initialized by the container and is null.
I have following configuration in my JBoss standalone.xml:
<subsystem xmlns="urn:jboss:domain:mail:1.0">
<mail-session jndi-name="java:jboss/mail/Default">
<smtp-server outbound-socket-binding-ref="mail-smtp">
</smtp-server>
</mail-session>
</subsystem>
Any Idea why mailSession is not initialized by the container?
Although this is a web application, I need to do some initialization prior to HTTP requests, that's why I'm using an @StartUp class and other stuff.
Regards