java - Cannot inject javax.mail.Session, jboss 7.1.1 -


jboss can't inject smtp server configuration session field.

i've edited standalone.xml file:

<mail-session jndi-name="java:jboss/mail/mymail">         <smtp-server outbound-socket-binding-ref="mail-smtp-my-mail">                <login name="login" password="passwd"/>         </smtp-server> </mail-session> ... <socket-binding-group ...>     <outbound-socket-binding name="mail-smtp-my-mail">         <remote-destination host="my-stmp-server" port="2587"/>     </outbound-socket-binding> 

my class has session field:

@stateless public class mailhelper {      @resource(mappedname = "java:jboss/mail/mymail")     private session mailsession;      public string send() {         mimemessage m = new mimemessage(mailsession);         try {             m.setrecipients(message.recipienttype.to, "g@gmail.com");             transport.send(m);         } catch (messagingexception e) {             e.printstacktrace();         }         return "...";     } } 

mail helper used in jsp page:

<%@page contenttype="text/html" pageencoding="utf-8"%> <!doctype html public "-//w3c//dtd html 4.01 transitional//en"     "http://www.w3.org/tr/html4/loose.dtd">  <html>     <head>     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>jsp page</title> </head> <body>     <h1>hello world!</h1>     <jsp:usebean id="mailhelper" class="com.mailhelper" scope="session"/>     <%= mailhelper.send()%> </body> 

every time have null in mailsession field. wrong?

the mailsession , outbound-socket configured correctly. in slsb mailhandler, availabe under java:global/yourproj/mailhelper!youpackage.mailhelper , on, there must injected session. there should in server.log:

java:global/testjsp/mailhelper!example.mailhelper java:app/testjsp/mailhelper!example.mailhelper java:module/mailhelper!example.mailhelper java:global/testjsp/mailhelper java:app/testjsp/mailhelper java:module/mailhelper 

otherwise project not deployed. mailhelper in context of org.apache.jasper.servlet.jspservlet javabean not slsb. have no di there. can lookup javax.mail.session manually in way

 public string send(){     try {         context c = new initialcontext();         session = (session)c.lookup("java:jboss/mail/mymail");         system.out.println();     } catch (exception e) {         e.printstacktrace();     }     return ""; } 

or instantiate in standard constructor:

  public mailhelper() {    ini(); }  void ini(){     try {         context c = new initialcontext();         session = (session)c.lookup("java:jboss/mail/mymail");               } catch (exception e) {         e.printstacktrace();     } } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -