Question

I am running EJB application with RAD+Webshere-8.5.1. I have to add send email functionality in my EJB, for that I configured dummy mail session in IBM console application as follow enter image description here

And I am trying to access in my Stateless Ejb as

@Resource(name="mail/sandMailSession")
private Session sandMailSession;

But its failing, as NameNotFoundException.

Do we required other setting to bind?

Was it helpful?

Solution

'mail/sandMailSession' is the name defined in the global namespace. You should bind mail session to the local component namespace by using ibm-ejb-jar-bnd.xml file inside META-INF directory:

<ejb-jar-bnd xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
    xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd" version="1.0">
  <session name="NAME_OF_EJB">
    <resource-ref name="mail/sandMailSession" binding-name="mail/sandMailSession"/>
  </session>
</ejb-jar-bnd>

Please note that name and binding-name are separate attributes and can have different values, although in your case they are the same. binding-name is the name of a resource in the global namespace.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top